Sub topic 4
Choosing a valid, unique username
This chapter assumes you have a Developer Edition sign-up form open or nearly complete, and that you know what a Salesforce org is. You do not need CLI experience yet, although the username you pick is the same one the CLI will use later.
Why the username needs care
A Salesforce username is the login name for a user in an org. It is separate from your email address, even though it looks like one. Salesforce requires usernames to follow an email-address format, such as [email protected], but the username does not have to be a real mailbox.
Two facts drive most sign-up problems:
- A username must be unique across all Salesforce orgs in the world, not only inside your own org.
- Once the org exists, changing the username is possible but affects logins, saved CLI authorizations, and any integrations that use it.
Your email address, by contrast, can be shared. Many people use the same email for several orgs. Only the username must differ.
The rules
| Rule | Valid example | Invalid example |
|---|---|---|
| Email-address format with `@` and a domain | `[email protected]` | `jane.dev` |
| No spaces | `[email protected]` | `jane [email protected]` |
| Globally unique | `[email protected]` | A name already used in any org |
| Maximum 80 characters | A short, readable name | A very long generated string |
The domain part does not need to exist or receive mail. Salesforce does not send messages to the username. Verification and notices go to the email address field.
A naming pattern that works
Because common names are often taken, build the username from parts that make collisions unlikely:
- Your name, in the form
first.last. - A purpose tag, such as
devorsfdx. - A year or number if needed.
- A domain you control, or a clearly made-up one.
For example: [email protected].
Use a domain you own if you have one. A made-up domain is allowed, but another person could later pick a similar username in that domain, and you would gain nothing from the match.
What happens when you submit
Salesforce checks the format first, then checks uniqueness. If the name is taken, the form shows an error and does not create the org. You can edit the field and submit again.
Common errors
- "Username already exists": another org holds that name. Add a tag or number and resubmit. Do not assume the earlier org is yours. It may belong to someone else, or to an older org of yours that you forgot.
- Invalid format: the field is missing the
@or the domain, or it contains a space. - Confusing username and email: entering your email in the username field often fails on uniqueness, because someone, possibly you, already used it as a username. Use a distinct username and keep the real email in the email field.
- Typo in the email field: the username can be correct while the verification email goes to the wrong address. The next chapter covers that.
Where you will see it again
The username appears on the login page, in your user record in Setup, and in the output of CLI commands such as sf org list. It also appears when you run this anonymous Apex to confirm which user you are:
System.debug('User: ' + UserInfo.getUserName());If the debug log shows a different username from the one you intended, you are signed in to a different org or user.
Exercise
Your first choice, [email protected], is rejected as already in use, but your email address is still [email protected]. What should you change, and why can you keep the email address?
Show answer
Change only the username, for example to [email protected]. Usernames must be unique across all Salesforce orgs, but email addresses are not required to be unique. Verification mail goes to the email field, so the same address can stay there.
Exercise
Which of these usernames is invalid: [email protected], sam [email protected], [email protected]?
Show answer
sam [email protected] is invalid because it contains a space. The other two have a valid email-style format.