Sub topic 10
Permission set groups: bundling permission sets by job function
This chapter assumes you know what a profile and a permission set are, and that a permission set adds access on top of a profile. It also assumes you can find Permission Sets in Setup and know what a user record is. Muting permission sets and the group status values get their own chapters, so this chapter covers them only briefly.
Why groups exist
A single permission set usually covers one task, such as "read Accounts" or "approve discounts". A real job needs many tasks. A sales rep might need five or six permission sets. If you assign each one to each user, you get these problems:
- Onboarding a new rep means repeating five or six assignments.
- When the job changes, you must find every user and edit each one.
- Nobody can see at a glance which permission sets make up "a sales rep".
A permission set group (PSG) fixes this. It is a named bundle of permission sets. You assign the group to a user, and the user receives the combined permissions of every permission set in it.
The working model
A group has no permissions of its own. It is a list of permission sets, plus an optional muting permission set. When a user is assigned the group, Salesforce calculates the union of all permissions in the member permission sets. That result is what the user receives.
Three rules follow from this model:
- Access is additive. The group adds to what the profile already grants. It never lowers profile access, except through muting inside the group.
- A user can hold several groups and standalone permission sets at the same time. Salesforce combines all of them.
- Muting applies only to permissions that come from the group it belongs to. If the same permission arrives from the profile or from another assignment, it remains.
Defining a group in metadata
A group is metadata of type PermissionSetGroup. The following file bundles two permission sets by API name, not by label.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSetGroup xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Sales Representative</label>
<description>Everything a sales rep needs</description>
<permissionSets>Account_Viewer</permissionSets>
<permissionSets>Opportunity_Editor</permissionSets>
</PermissionSetGroup>Each permissionSets element names one member. To add a muting permission set, you add a mutingPermissionSets element with its API name. The file would be saved as Sales_Representative.permissionsetgroup-meta.xml in the permissionsetgroups folder of a source project.
The member Account_Viewer is the permission set from earlier in this tutorial. It grants read access to Account and read-only field-level security on Account.AnnualRevenue.
<?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>Building a group in Setup
- In Setup, open Permission Set Groups and choose New Permission Set Group.
- Enter a label, an API name, and a description. Describe the job function, because administrators read this later.
- Save, then open Permission Sets in Group and add the member permission sets.
- Optionally add a muting permission set (see the muting chapter).
- Assign the group to users from Manage Assignments.
After you save a change to membership, Salesforce recalculates the combined permissions. Large changes take time, and the group has a status that tells you whether the result is current. The status values (Updated, Updating, Outdated, Failed) are covered in a later chapter.
Assigning a group
Assigning a group uses the same object as assigning a permission set: PermissionSetAssignment. The only difference is that you set PermissionSetGroupId instead of PermissionSetId.
PermissionSetGroup psg = [
SELECT Id
FROM PermissionSetGroup
WHERE DeveloperName = 'Sales_Representative'
LIMIT 1
];
User u = [SELECT Id FROM User WHERE Username = '[email protected]' LIMIT 1];
insert new PermissionSetAssignment(
AssigneeId = u.Id,
PermissionSetGroupId = psg.Id
);The query filters on DeveloperName, which holds the API name of the group. The assignment record itself is the same kind of record you create for a standalone permission set. Only the target field differs.
How a group treats licenses
Permission sets can be tied to a user license or to a permission set license. A group can contain permission sets with different license requirements. If a user lacks a license that a member needs, Salesforce does not give that member's license-dependent permissions to the user. Check license compatibility when you assign a group to users with different license types, and confirm the result in the user's assignment list.
Decision criteria
Use a group when several permission sets always travel together for a role. Use a standalone permission set when the access is an optional extra that only some people in a role need.
| Situation | Use |
|---|---|
| Everyone in a job function needs the same set of permission sets | A permission set group |
| A few people need a one-off extra | A standalone permission set |
| A role needs a group minus one permission | A group with a muting permission set |
| Access depends on a user's profile only | Neither. Change the profile or move the access into a permission set |
Common errors
- Assigning members and the group together. If a user holds both a group and one of its member permission sets, the access is the same, but you now have two things to remove at offboarding. Pick one route per user.
- Expecting muting to override the profile. A muting permission set removes permissions only within its own group. If the profile grants the permission, the user keeps it.
- Forgetting that a group does not hold profile-only settings. Default app, record type defaults, page layout assignment, and login restrictions cannot be expressed in a group the way they can in a profile. Check the profile chapter for what stays there.
- Naming by technology instead of job. A group called
Permissions_Batch_2tells nobody anything. Name groups after job functions, such asSales_Representative. - Testing before recalculation finishes. If you test a user right after changing a group, the combined permissions might be out of date. Check the group status first.
Auditing group assignments
The SOQL below lists who holds which permission sets. It 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.NameGroup assignments appear in the same object, so the query shows them too. For a group assignment, the PermissionSetGroupId field on the row is populated. Salesforce also creates assignment rows for the member permission sets that come from the group, so one group assignment can appear as several rows. Include PermissionSetGroupId in the select list when you need to tell the two kinds apart.
Exercise
A user holds the Sales Representative group, which includes Opportunity Editor. The profile also grants Delete on Opportunity. An admin adds a muting permission set to the group that turns off Delete on Opportunity. Can the user still delete opportunities, and why?
Show answer
Yes. Muting removes a permission only as it arrives through its own group. The profile grants Delete separately, and access is additive, so the user keeps it. To remove it, change the profile or move the grant into a permission set that can be controlled.
Exercise
Write the two changes needed to give an existing group a third member permission set named Case_Reader, using metadata.
Show answer
Create a CaseReader permission set file if it does not exist, then add a third line to the group file: <permissionSets>CaseReader</permissionSets>. Deploy both, and then check the group status for recalculation.