Sub topic 9
Creating a user in Setup, step by step
This chapter walks through creating one user in Setup. It assumes you already know what a user licence, a profile and a permission set are, and that you can open Setup in Lightning Experience. You need the Manage Users permission, or the System Administrator profile, in a sandbox or a Developer Edition org.
Before you start
A user record is easy to create and hard to undo. Users cannot be deleted. They can only be deactivated, and the username stays reserved. Spend two minutes on the checks below before you click Save.
- Confirm a licence is free. Run the first query below in the Developer Console or Workbench, or open Company Information in Setup.
- Choose the profile. The profile decides which user licence the new user consumes.
- Decide the role, if your org uses a role hierarchy.
- List the permission sets the person needs on day one.
This query lists each user licence with its total and used counts:
SELECT Name, TotalLicenses, UsedLicenses
FROM UserLicense
ORDER BY NameIf UsedLicenses equals TotalLicenses for the licence you need, saving the user fails. Free a licence by deactivating someone, or ask Salesforce to add more.
The flow at a glance
Step by step in Setup
1. Open the new user form
- Click the gear icon, then Setup.
- In Quick Find, type
Users, then select Users under Users. - Click New User.
The page you land on is the classic user edit form, even inside Lightning Experience. The fields are grouped into General Information, Locale Settings, Approver Settings, and a few other sections that depend on which features are on.
2. Fill in the required fields
Salesforce requires the fields below. The form marks them with a red bar.
| Field | What it does | Notes |
|---|---|---|
| First Name | Given name | Optional in the API, but fill it in for clean lists and search. |
| Last Name | Family name | Required. |
| Alias | Short name shown in some list views and reports | Required. Up to eight characters. Setup suggests one from the name. |
| Where notifications and the login link go | Required. Must be a real address you control or the person controls. | |
| Username | The login name | Required. Must look like an email address and be unique across all Salesforce orgs. |
| Nickname | Display name used in Experience Cloud and Chatter | Required in the form. Setup suggests one. |
| User License | The licence the user consumes | Required. Choose it before the profile. |
| Profile | Baseline permissions | Required. Only profiles compatible with the chosen licence are listed. |
| Role | Position in the role hierarchy | Optional, but it affects record visibility. |
| Time Zone | Time zone for date and time display | Required. Defaults to your own. |
| Locale | Format of dates, numbers and currencies | Required. |
| Language | Language of the interface | Required. |
| Email Encoding | Character set for outbound email | Required. `Unicode (UTF-8)` is the usual choice. |
3. Username rules
The username has more rules than the other fields.
- It must be in email address format, such as
[email protected]. It does not have to be a working mailbox. - It must be unique across every Salesforce org, not only yours. A name like
[email protected]is often taken already. - It is not the same as the Email field. Many orgs use a username that differs from the email, for example by adding a suffix for a sandbox.
- After the user exists, you can change the username, but the user must then log in with the new value. Tell them before you do it.
A common pattern is to use the person's work email plus a suffix that marks the org, for example .demo, .dev or .uat. Sandboxes automatically append the sandbox name to usernames when the sandbox is created or refreshed, which is why a production username like [email protected] becomes [email protected] there.
4. Pick the licence, then the profile
Choose User License first. The Profile picklist then shows only profiles that belong to that licence. If you pick a profile first and then change the licence, the profile resets.
For a standard employee, pick Salesforce as the licence and a profile such as Standard User. Chapters on profiles and least privilege cover how to choose the right profile. For now, remember the rule: the licence sets the ceiling of what a profile can offer, and the profile sets the baseline for the user.
Some licences, such as Salesforce Platform, include fewer standard objects. If the user needs Opportunities, a Platform licence will not allow it, regardless of the permission set.
5. Set the role (optional)
The role places the user in the role hierarchy. It controls which records the user can see through the hierarchy, not what the user can do with them. Leave it blank if your sharing model does not use roles, or if you are not sure. You can add it later. Users without a role see only what the org-wide defaults and sharing rules give them, plus records they own.
6. Decide how the user gets the login email
At the bottom of the form is the checkbox Generate new password and notify user immediately.
- If it is checked, Salesforce sends the user an email with a link to set a password. This is the usual choice.
- If it is cleared, no email is sent. You can then send the link later with Reset Password on the user detail page. Leave it cleared when you create users in a sandbox in bulk and do not want to email real people.
The email goes to the Email field, so a typo there means the invitation lands in someone else's inbox.
7. Save
Click Save. Salesforce opens the user detail page. The record is active by default, and the licence is now consumed. If the form returns an error, the next section explains the common ones.
When Save fails
| Message (summarised) | Cause | Fix |
|---|---|---|
| Duplicate username | Another user in any org already has the username | Change the username, for example by adding a suffix. |
| License limit exceeded | No free licences of the selected type | Deactivate an unused user or add licences. |
| Invalid email address | Email is malformed | Correct the Email field. |
| Required fields are missing | A mandatory field is blank | Fill in the field named in the message. |
| Profile not available | The profile does not match the licence | Reselect the licence, then the profile. |
A failed save does not consume a licence and does not create a half-made user. You can correct the form and save again.
Create the same user with Apex
Setup is the right tool for one person. For repeatable setups, such as a scripted sandbox, the same user can be created in Anonymous Apex. The required fields are identical, and so are the rules.
Profile p = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
User u = new User(
FirstName = 'Ada',
LastName = 'Lovelace',
Alias = 'alove',
Email = '[email protected]',
Username = '[email protected]',
ProfileId = p.Id,
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US'
);
insert u;The licence is implied by the profile, so the code never sets one. Apex also skips the nickname requirement, because CommunityNickname is only required for some user types. Chapters later in this tutorial cover the Apex route and permission set assignment in more detail.
Verify the result
After saving, check three things on the user detail page.
- Active is selected.
- User License and Profile show the values you intended.
- Under Permission Set Assignments, you see only what you expect. A new user has none unless you added them.
You can also confirm the licence count has risen by one by running the licence query again. Then continue with permission sets in the next chapter.
Common mistakes
- Choosing the profile before the licence, then wondering why the picklist is short.
- Reusing the email address as the username in an org family where the same person already exists elsewhere.
- Leaving the notification checkbox ticked in a sandbox and emailing real staff.
- Giving the new user a powerful profile because it is quicker than building a permission set.
- Forgetting that a licence is consumed the moment the record saves as active.
Exercise
You click Save on a new user and see a "duplicate username" error, even though nobody in your org has that username. What is the likely cause, and what is a safe fix?
Show answer
Usernames must be unique across all Salesforce orgs, not only your own, so another org already uses it. Change the username to a still-valid email-style value that is unlikely to collide, for example by adding a suffix such as .demo or your company domain. The Email field can stay the same.
Exercise
A user is created with the profile Standard User, and you then notice the licence count did not change as you expected. Which setting determined which licence was consumed, and where do you verify it?
Show answer
The profile determines the licence, because each profile belongs to exactly one user licence. Verify it in the User License field on the user's detail page, or by running SELECT Name, TotalLicenses, UsedLicenses FROM UserLicense before and after creating the user.