Sub topic 5
Granting access with permission sets
This chapter assumes you know basic Salesforce administration (users, profiles, objects, fields) and have a sandbox or Developer Edition org with admin rights. You should also be comfortable reading SOQL. By the end, you will build a permission set for the integration user, assign it, and check what it grants.
Why permission sets carry the access
A profile is the base of a user's access. A permission set adds to it. Permissions only accumulate, so the user's effective access is the profile plus every assigned permission set. A permission set can never take away something the profile already grants.
This shapes the design. Keep the profile as small as possible, then grant everything the integration needs in a permission set that has one clear purpose. A named set such as Integration Account Read is easy to review, easy to reuse, and easy to remove.
What goes in the permission set
For an API-only integration, three kinds of permission matter:
- System permission.
ApiEnabledlets the user call the APIs at all. Without it, every request fails. - Object permissions. Read, Create, Edit, and Delete, plus View All and Modify All.
- Field permissions. Readable and editable, set per field.
Grant only what your requirements list from the earlier chapter says. A read-only integration needs Read on its objects. It does not need Create, Edit, or Delete.
A read-only permission set
The following permission set is in metadata format. It enables API access and gives read-only access to the Account object and one field.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Read-only access to Account for the integration user</description>
<fieldPermissions>
<editable>false</editable>
<field>Account.Industry</field>
<readable>true</readable>
</fieldPermissions>
<hasActivationRequired>false</hasActivationRequired>
<label>Integration Account Read</label>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Account</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ApiEnabled</name>
</userPermissions>
</PermissionSet>Points to notice:
- Every create, edit, and delete flag is
false. Setting flags tofalseexplicitly makes the intent clear to reviewers. viewAllRecordsandmodifyAllRecordsarefalse. These two flags bypass the sharing model for the object, so they are the most dangerous to grant by accident.hasActivationRequiredisfalse, so the permission set is active whenever it is assigned.- Field access is listed per field. Fields not listed are not readable by this permission set, unless the profile or another permission set grants them.
Assigning the permission set
Assign the permission set to the integration user in Setup, under the user's Permission Set Assignments. You can also deploy the metadata with the Salesforce CLI and then assign it.
After assigning, list everything the user holds. This query shows every permission set and every profile-owned permission set assigned to the user. Replace the Id with your integration user's Id.
SELECT PermissionSet.Name, PermissionSet.Label, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'You should see the profile's own permission set (where IsOwnedByProfile is true) and Integration_Account_Read. Anything else needs an explanation.
Inspecting the object permissions
To see what one permission set grants at the object level, query ObjectPermissions. This makes stray Delete, View All, or Modify All flags easy to spot.
SELECT SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE Parent.Name = 'Integration_Account_Read'For this permission set, you should get one row for Account with only PermissionsRead set to true.
Common mistakes
- Granting access in the profile. It is harder to audit and cannot be reused. Put grants in permission sets.
- Cloning an admin or standard profile. The clone carries every permission of the original.
- Using View All Data or Modify All Data. These system permissions override object and field settings. An integration almost never needs them.
- Adding permissions "to see if it works." Add one permission at a time, driven by an actual error, and remove anything that turns out to be unneeded.
Exercise
The integration user's profile already allows Delete on Contact. You build a permission set that sets allowDelete to false for Contact and assign it. Can the integration user delete contacts?
Show answer
Yes. Permissions are additive, and a permission set cannot remove what the profile grants. To stop deletion, remove the permission from the profile, or move the user to a minimal profile and grant only the needed access through permission sets.
Exercise
Which two object-level flags in a permission set bypass the sharing model, and why should a read-only integration leave them false?
Show answer
viewAllRecords and modifyAllRecords. They give access to every record of the object regardless of sharing, so enabling them widens the integration's access well beyond what its requirements need.