Sub topic 3
Assigning Permission Sets and Licences to a New User
Assume you have administrator access and basic familiarity with Setup, SOQL, and Apex. A profile supplies the user licence and baseline permissions. A permission set adds permissions without changing the profile. A permission set licence grants access to a feature that requires its own licence.
Assigning Access
Open Setup > Users > Users, select the user, and use Permission Set Assignments to add a permission set. If the set requires a permission set licence, assign that licence first from the user’s Permission Set License Assignments section.
Designing Least-Privilege Access
Least privilege means giving only the access needed for the user’s work.
- Choose the narrowest compatible profile.
- Add extra object, field, or system permissions with permission sets.
- Prefer permission set groups for repeatable job functions.
- Do not use an administrator profile as a shortcut.
- Assign a role only when the user needs its record-visibility behavior.
Review assignments when a person changes roles or leaves the organization.
Creating Many Users
For a few users, choose Add Multiple Users from the Users page. For larger batches, use Data Loader with fields such as Username, Alias, ProfileId, TimeZoneSidKey, and LanguageLocaleKey. Usernames must be globally unique across Salesforce, not merely unique within your org. Check licence capacity before loading the file.
Creating Users with Apex
Execute Anonymous Apex can create a user and assign a permission set:
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;
PermissionSet ps = [
SELECT Id FROM PermissionSet
WHERE Name = 'Your_Permission_Set_API_Name' LIMIT 1
];
insert new PermissionSetAssignment(AssigneeId = u.Id, PermissionSetId = ps.Id);Replace the profile, username, and permission set values before running it.
Deactivating and Troubleshooting
Clear Active on a user record to deactivate the user. Salesforce users cannot be deleted because their records can be referenced by audit history and other data. Deactivation usually releases the user licence for reuse, but does not erase the user or immediately remove every historical reference.
Common errors include:
- Duplicate username: choose a globally unique username.
- No available licence: deactivate an unused user or purchase capacity.
- Invalid profile: select a profile compatible with the user licence.
- Permission set licence required: assign the required feature licence before the permission set.
Exercise
A new user needs one extra object permission but no new feature. Should you change the profile or assign a permission set?
Show answer
Assign a permission set. It adds the required access while keeping the profile and baseline access unchanged.