Sub topic 5
Extending access with permission sets and groups
This chapter assumes you know what a user licence and a profile are, and that you can open Setup and find the Users and Permission Sets pages. It covers how permission sets add access on top of a profile, how permission set groups bundle them, and the errors you will meet when you assign them.
Why permission sets exist
A profile gives a user their baseline access, and every user has exactly one. If you only had profiles, any user who needed one extra permission would need a new profile. Orgs that work this way end up with dozens of near-identical profiles that are hard to maintain.
A permission set is a collection of settings and permissions that you add to a user without changing their profile. A user can have many permission sets. Access is additive: the user gets the union of the profile and every assigned permission set. A permission set can grant access, but it cannot take access away.
A permission set can grant:
- Object permissions (Read, Create, Edit, Delete, View All, Modify All).
- Field-level security (read or edit access on individual fields).
- System permissions, such as Manage Users or Export Reports.
- Access to Apex classes, Visualforce pages, custom permissions, and connected apps.
- Visibility of apps, tabs, and record types.
The user's licence limits what a permission set can contain. A permission set can only grant permissions that the user's licence allows. You can also create a permission set that is tied to a licence, so that it can be assigned only to users who have that licence.
How access combines
The platform evaluates access by taking the most permissive setting for each permission across the profile and all assigned permission sets and groups. If the profile denies Delete on Account and one permission set grants it, the user can delete accounts.
Creating a permission set
- In Setup, enter
Permission Setsin Quick Find and select it. - Click New.
- Enter a Label. The API Name is generated from it. The API name is what code and deployments use, so choose a label you will not want to change.
- Choose a License. Select --None-- to make the set assignable to users with any licence. Select a specific licence to make the set assignable only to users with that licence, which also lets it include permissions that only that licence supports.
- Click Save.
- Open the sections you need, such as Object Settings or System Permissions, and choose the permissions.
The licence choice cannot be changed after you save, so check it before you click Save.
Choosing the licence setting
| Licence setting | Who can be assigned | Permissions available |
|---|---|---|
| None | Any active user | Only permissions that every licence supports |
| A specific user licence | Only users with that licence | Permissions that licence supports |
A permission set with no licence is the most flexible. If you assign it to a user whose licence does not support one of the permissions inside, that permission is not granted.
Permission set groups
A permission set group is a container that bundles several permission sets so that you can assign them in one step. Use a group when a job role needs the same collection of permissions each time, for example "Sales Support" or "Service Agent".
Groups have these properties:
- You assign the group to users. The user then receives the combined permissions of every permission set inside.
- Changing a member permission set changes access for every user who has the group.
- A group has a status that shows whether its combined permissions are up to date. After you edit a member permission set, the group recalculates. While it recalculates, the status is Updating. When it finishes, it is Updated. A group that is not ready cannot be assigned.
- A group can contain a muting permission set. Muting turns off selected permissions within that group only.
Muting permission sets
Muting is the one place where permission sets can effectively reduce access. Suppose the group "Sales Support" includes a permission set "Case Management" that grants Delete on Case. You want most of that set, but not Delete. You can add a muting permission set to the group and mute Delete on Case.
- Muting affects only the group it belongs to.
- If the user also receives Delete on Case from their profile or from a permission set assigned directly (not through the group), muting does not remove it.
- Muting is not a way to restrict the profile.
That last point matters for least-privilege design, which a later chapter covers: to remove access, you must remove it at its source.
Choosing between a set and a group
| Situation | Use |
|---|---|
| One narrow capability needed by a few people | A single permission set |
| A role needs several permissions together | A permission set group |
| A role needs most of an existing set, minus a few permissions | A group with a muting permission set |
| Everyone with a profile needs the same thing | Put it in the profile or consider a group assigned to all |
Assigning permission sets and groups
You can assign from either direction.
From the user record
- In Setup, open Users, then select the user.
- In the Permission Set Assignments related list, click Edit Assignments.
- Move permission sets to the Enabled list.
- Click Save.
For groups, use the Permission Set Group Assignments related list in the same way.
From the permission set
- Open the permission set in Setup.
- Click Manage Assignments.
- Click Add Assignments, select users, and click Assign.
This direction is faster when you give one set to many users.
Assigning with Apex
Each assignment is a PermissionSetAssignment record. For a group, you set PermissionSetGroupId instead of PermissionSetId. The code below assigns a permission set to a user and skips the insert if the assignment already exists, which avoids a duplicate error.
String userName = '[email protected]';
String psName = 'Your_Permission_Set_API_Name';
User u = [SELECT Id FROM User WHERE Username = :userName LIMIT 1];
PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = :psName LIMIT 1];
List<PermissionSetAssignment> existing = [
SELECT Id FROM PermissionSetAssignment
WHERE AssigneeId = :u.Id AND PermissionSetId = :ps.Id
];
if (existing.isEmpty()) {
insert new PermissionSetAssignment(AssigneeId = u.Id, PermissionSetId = ps.Id);
}Replace the placeholder API name with a real one before you run it. The query uses the Name field, which holds the API name, not the label.
Reviewing who has what
To audit access, query the assignment object. This query lists the permission sets assigned to one user. Profiles also appear in this object as hidden permission sets, so the query filters them out.
SELECT PermissionSet.Label, PermissionSet.Name
FROM PermissionSetAssignment
WHERE Assignee.Username = '[email protected]'
AND PermissionSet.IsOwnedByProfile = false
ORDER BY PermissionSet.LabelEach profile has an underlying permission set record that stores its settings. That is why IsOwnedByProfile exists.
Common errors and edge cases
- Licence mismatch. Assigning a permission set that is tied to a licence the user does not have fails with an error that the licence is not compatible. Check the permission set's licence against the user's licence.
- Missing permission set licence. Some permission sets include permissions that need a permission set licence. The assignment fails until the user has that licence. The next chapter covers these.
- Duplicate assignment. Inserting an assignment that already exists fails with a duplicate error. Query first, as the Apex example does.
- Group not ready. You cannot assign a group while its status is Updating or Failed. Wait for it to finish, or open the group and fix the failed member.
- Deactivated users. Assignments remain on a deactivated user. They apply again if you reactivate the user.
- Profile changes. Changing a user's profile does not remove their permission sets. Review them after the change, because permission sets that were added to compensate for the old profile may no longer be needed.
- Muting expectations. Muting does not override access that comes from outside the group.
Putting it together
A new support agent has the Standard User profile. They need to edit cases, run reports, and see a custom Knowledge app. You create three small permission sets, one per capability, bundle them in a "Service Agent" group, and assign the group. When the Knowledge app later needs an extra object permission, you edit one permission set, and every agent receives it once the group finishes updating.
Exercise
A user has a profile that grants Delete on Case. You add a muting permission set to a permission set group that the user holds, and mute Delete on Case. Can the user still delete cases, and why?
Show answer
Yes. Muting only removes the permission that comes through that group. The profile still grants Delete on Case, and access is the union of the profile and all assignments, so the user keeps the permission. To remove it, change the profile or use a profile that does not grant it.
Exercise
You try to assign a new permission set group to a user and the option is unavailable. The group's status shows Updating. What should you do?
Show answer
Wait until the status changes to Updated, then assign the group. If the status shows Failed, open the group, find the member permission set that caused the failure, fix it, and let the group recalculate.