Sub topic 8
Permission Sets: Additive Access on Top of a Profile
This chapter assumes you know what a profile is, how object permissions and field-level security work, and the difference between permissions and record sharing. If any of those are unclear, review the earlier chapters first.
What a permission set is
A permission set is a named collection of permissions that you assign to users on top of their profile. Every user has exactly one profile. A user can also have many permission sets. The permission sets add access. They never take it away.
This gives you one rule to remember: a user's effective access is the union of their profile and all assigned permission sets. If any one of them grants a permission, the user has it.
Why use them
Profiles are one per user. If two sales reps need the same baseline but only one needs to edit Opportunities, a profile-only design forces you to clone the profile. After a few rounds of this you have dozens of near-identical profiles, and every change has to be repeated in each one.
Permission sets solve this. Keep a small number of profiles, and grant the differences with permission sets. Each permission set describes one capability, such as "Account Viewer" or "Approve Discounts", and you assign it only to the users who need it.
What a permission set can contain
A permission set can grant many of the same things a profile can:
- Object permissions: Create, Read, Edit, Delete, View All, Modify All.
- Field permissions: Read and Edit on individual fields.
- System permissions, such as "Run Reports" or "Export Reports".
- Custom permissions, which gate your own features.
- Access to Apex classes, Visualforce pages, and flows.
- Visibility of apps, tabs, and record types.
- Settings that need a specific permission set license.
Some settings still live only on the profile. Page layout assignments, login hours, and login IP ranges are examples. Check the earlier chapter on profile-only settings before you plan to move everything.
A permission set cannot reduce access. Read-only on a field in a permission set does not override Edit on that field in the profile. The user still gets Edit.
A permission set in metadata form
The following permission set grants read access to Account and read-only field-level security on Annual Revenue. It is written in the Metadata API format, which you will use again when deploying.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Account Viewer</label>
<description>Read-only access to Accounts and the Annual Revenue field</description>
<hasActivationRequired>false</hasActivationRequired>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Account</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Account.AnnualRevenue</field>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>Points to notice:
labelis what admins see. The API name, which Apex and deployments use, is the file name without the extension, for exampleAccount_Viewer.- Each
objectPermissionsblock names one object and lists all seven flags explicitly. fieldPermissionsentries useObject.Fieldformat. Settingeditabletotruerequiresreadableto betrue.hasActivationRequiredisfalse, so the permission set takes effect as soon as it is assigned. The next section explains the alternative.
Session-based permission sets
If you set hasActivationRequired to true, the permission set is session-based. Assigning it does not grant access on its own. The user must also activate it in their current session, for example through a flow. This is useful for elevated access that should be temporary. Most permission sets do not need it.
Creating a permission set in Setup
- Go to Setup and search for Permission Sets.
- Click New, enter a label and API name, and save.
- Choose a license option. Leave it as None unless the permission set needs features tied to a specific license (the next chapter covers this).
- Open the sections you need, such as Object Settings, and set the permissions.
- Assign users with Manage Assignments.
Object Settings is where most of the work happens. Opening an object shows its object permissions and a list of its fields, so you can set field-level security in the same place.
Assigning permission sets with Apex
Behind the scenes, an assignment is a PermissionSetAssignment record. It links a user (AssigneeId) to a permission set (PermissionSetId). You can create one in code:
PermissionSet ps = [
SELECT Id
FROM PermissionSet
WHERE Name = 'Account_Viewer'
LIMIT 1
];
User u = [SELECT Id FROM User WHERE Username = '[email protected]' LIMIT 1];
insert new PermissionSetAssignment(
AssigneeId = u.Id,
PermissionSetId = ps.Id
);Match on Name, which is the API name, not Label. Labels can change and are not unique guarantees. The insert fails if the user already has the assignment, so query for an existing record first in any code that may run twice.
Seeing who has what
To list assignments, query PermissionSetAssignment. This query excludes the hidden permission set that Salesforce keeps for each profile:
SELECT Assignee.Name, PermissionSet.Name, PermissionSet.Label
FROM PermissionSetAssignment
WHERE PermissionSet.IsOwnedByProfile = false
ORDER BY Assignee.NameWithout the IsOwnedByProfile = false filter, every user appears with a row for their profile. Salesforce stores a profile's permissions as a permission set record internally, which is why this filter is needed.
Common errors
| Symptom | Likely cause |
|---|---|
| Assignment fails with a license error | The permission set requires a permission set license the user does not have, or the user license does not match. |
| User still cannot see records | Permissions grant object access only. Check sharing: org-wide defaults, roles, and sharing rules. |
| Field is still editable after you set it to read-only | Another permission set or the profile grants Edit. Access is the union. |
| Duplicate assignment error in Apex | The assignment already exists. Query before inserting. |
| Cannot remove a permission by editing a permission set | Permission sets only add. Remove it from the source that grants it, or use muting inside a permission set group (covered later). |
Design guidance
- Name each permission set after one capability or job task, not after a person or team.
- Keep permission sets small and single-purpose so they can be combined.
- Put the narrowest baseline on the profile and grant everything else through permission sets.
- Write a clear description. Admins reading the assignment list months later will rely on it.
Exercise
A user's profile gives Edit access to the Opportunity Amount field. You assign a permission set that grants only Read on that field. Can the user edit Amount? Why?
Show answer
Yes. Effective access is the union of the profile and all permission sets. The profile grants Edit, and a permission set cannot remove it. To make the field read-only for this user, change the profile (or move the user to a profile that does not grant Edit), or use a muting permission set within a permission set group.
Exercise
Write a SOQL query that lists the user name and permission set API name for every assignment, excluding profile-owned permission sets.
Show answer
SELECT Assignee.Name, PermissionSet.Name FROM PermissionSetAssignment WHERE PermissionSet.IsOwnedByProfile = false