How to create unique usernames?

I’m using FirstnameLastname to generate a username for new accounts.

If two users are created at the same time or later and have the same name.
One email will be designated the username the other email will be blank.


As they are copy field values, I don’t see a way to make them unique?

Note: We don’t wish to use email address as username.


Usernames have to be unique, so if you don’t want to use email address, can I suggest using the id of the user record as part of your composite instead - that is guaranteed to be unique.

If you wanted to write code, I guess you could always check the generated id against those that already exist, and add a 1 for the second one, 2 for the third etc.



Thanks @richk sorted!