Sub topic 4
Choosing a valid, unique username
This chapter assumes you have read the earlier chapters on org types and the sign-up form. You should know that a Developer Edition org is a free, separate Salesforce environment. You should also be comfortable running a command in a terminal for the CLI examples near the end.
The sign-up form asks for a username. Most people type something quickly and move on. The username becomes the identifier you use for every login, for the Salesforce CLI, and for later steps such as email verification. Changing it later is possible but disruptive. Getting it right the first time saves time.
What a username is in Salesforce
A Salesforce username is a login name written in the format of an email address, such as [email protected]. It has three properties that surprise many new users.
- It looks like an email address but is not one. Salesforce checks the shape (text, an at sign, a domain with a dot). It does not check whether the domain exists or whether a mailbox is behind it.
- It is separate from the Email field. The Email field on the sign-up form is where Salesforce sends the verification message. The username is only what you type on the login page. The two can be identical, but they do not have to be.
- It must be unique across all of Salesforce. Uniqueness is not limited to your org. No other user in any org, production or not, can hold the same username.
The third property is the source of most sign-up errors. You are picking a name from a shared global pool, so a generic name like [email protected] or [email protected] is probably taken.
The rules in practice
The following table lists the rules that matter when you fill in the form.
| Rule | What it means | Example of a problem |
|---|---|---|
| Email-address format | One `@`, text before it, and a domain with at least one dot after it | `adadev` or `ada@localhost` |
| Globally unique | No other Salesforce user anywhere has it | `[email protected]` |
| No spaces | Spaces are not valid in the name | `ada [email protected]` |
| Length limit | The field allows up to 80 characters | A very long name with a long domain |
| Need not be a real mailbox | The domain does not have to receive mail | `[email protected]` works |
Avoid unusual punctuation even where it might be accepted. Characters such as quotes, commas, and angle brackets cause trouble in other tools, such as shell commands, scripts, and CSV files.
Why you should not simply reuse your real email address
Many tutorials suggest using your real email address as the username. That works only if nobody else has used it as a Salesforce username. If you have ever signed up for a Trailhead account, a previous Developer Edition org, or a company org with that exact string, it is already taken. A duplicate fails sign-up with a message saying the username already exists or is in use. The exact wording varies.
A better habit is to separate the two values:
- Email: your real, working address. The verification message goes here. It can be reused across many orgs.
- Username: a unique string you invent. It follows the email format but carries a distinguishing part.
For example:
- Email:
[email protected] - Username:
[email protected]or[email protected]
The second style uses a domain you do not own. That is fine because Salesforce never sends mail to the username. However, if you ever need to be sure nobody else could collide with it, a domain you control is safer. Use a subdomain of a domain you own, or a name with a personal or project-specific part.
A naming convention that scales
You will probably create more than one org over time: one for learning Apex, one for experimenting with Flow, and one for a project. A consistent pattern avoids collisions and tells you which org is which in sf org list output.
A workable pattern is firstname.lastname.purpose@yourdomain:
The same pattern helps when a teammate has to look at your CLI output. They can tell which org each username points to.
Sandboxes follow a related rule. When a sandbox is created from a production org, Salesforce appends the sandbox name to each username, for example [email protected]. That is why the same person has different usernames in different environments. Scratch orgs get a generated username, so you do not choose one there. This is another reason the Developer Edition username is a deliberate decision: it is one of the few where you choose.
How the decision flows
The following diagram shows how to arrive at a username that passes the form.
Notice that uniqueness can only be tested by submitting. There is no public lookup tool to check availability beforehand. Expect to retry once or twice, and do not read a duplicate error as a sign that something is broken.
Checking the format before you submit
A small script can catch format errors before you submit the form. It cannot check global uniqueness, because that lives only inside Salesforce. This version uses only the Python standard library.
import re
import sys
# One @, no spaces, a dot in the domain, and a total length of 80 or less.
USERNAME_PATTERN = re.compile(r"^[^\s@]+@[^\s@]+\.[^\s@]+$")
MAX_LENGTH = 80
def check_username(candidate: str) -> list[str]:
"""Return a list of problems. An empty list means the format is acceptable."""
problems = []
if len(candidate) > MAX_LENGTH:
problems.append(f"longer than {MAX_LENGTH} characters ({len(candidate)})")
if " " in candidate:
problems.append("contains a space")
if not USERNAME_PATTERN.match(candidate):
problems.append("does not look like [email protected]")
return problems
if __name__ == "__main__":
for name in sys.argv[1:]:
issues = check_username(name)
print(f"{name}: {'OK (format only)' if not issues else '; '.join(issues)}")Run it with several candidates:
python check_username.py [email protected] "ada [email protected]" adadevThe first candidate passes. The second fails on the space. The third fails the format check. A pass means only that the format looks right. Salesforce still decides whether the name is free.
What happens after the username is accepted
Once the form is accepted, Salesforce creates the org and sends a verification email to the address in the Email field, not to the username. The next chapter covers that step. Keep two things in mind now.
- The username shown on the login page is the one you typed. If you later forget which one you chose, search your inbox for the verification message. It names the username.
- Mistyping the Email field is worse than mistyping the username. A wrong username can be seen and fixed. A wrong email sends the verification message to the wrong person, and you cannot finish setup.
Seeing your username afterwards
After login you can confirm the username in several places. The CLI makes it easy to see the same value Salesforce stores.
sf org list
sf org display --target-org my-dev-orgsf org list shows the alias, the username, and the org ID for each authorized org. sf org display prints the details of one org, including the username and the instance URL.
You can also query the stored value with SOQL, the Salesforce query language:
sf data query --target-org my-dev-org --query "SELECT Username, Email FROM User WHERE IsActive = true"On a new Developer Edition org, the result includes your user, and you will see whether the username and email match. The org also contains system users, so more than one row may come back.
In anonymous Apex, which you can run from the Developer Console, one line writes the username to the debug log:
System.debug('Username: ' + UserInfo.getUserName());Changing a username later
An administrator can edit a username under Setup > Users > Users by opening the user record and choosing Edit. In a Developer Edition org you are the administrator, so you can do this yourself. The new value must still be in email format and globally unique. Salesforce typically sends a notification about the change to the user's email address.
Changing a username has side effects:
- Saved logins in browsers and password managers stop working.
- Existing CLI authorizations still point to the old username and may need to be redone.
- Scripts and configuration files that mention the old username break.
For these reasons, treat the username as fixed. Edit it only when you have a real reason, such as a typo or a naming change.
Common mistakes
- Using a generic name. Names like
[email protected]or[email protected]are almost always taken. Add a personal and purpose-specific part. - Assuming the username must be your real mailbox. It only has to look like an email address.
- Confusing username and email in the form. Check each field before pressing the sign-up button.
- Using spaces or odd symbols. Stick to letters, digits, dots, hyphens, and underscores.
- Not recording the choice. Write the username in a password manager now. You will need it at login, when you register multi-factor authentication, and when you authorize the CLI.
Exercises
Exercise
A learner enters [email protected] as the Developer Edition username and receives an error that the username is already in use. Her real email address is the same string. What should she change, and which field should keep her real address?
Show answer
She should change only the Username field, for example to [email protected], or use a different domain. The Email field should keep her real address [email protected], because the verification message is sent there. The username only needs to be email-formatted and globally unique.
Exercise
Which of these usernames would fail a format check, and why? (1) [email protected] (2) sam [email protected] (3) samlee.example.dev
Show answer
Option 2 fails because it contains a space. Option 3 fails because it has no at sign, so it is not in email format. Option 1 passes the format check, but only Salesforce can confirm it is unique.
Exercise
Name two things that can break after an administrator changes a username in an existing org.
Show answer
Any two of these: saved browser or password-manager logins, existing Salesforce CLI authorizations that refer to the old username, and scripts or configuration files that contain the old username.