Sub topic 6
Object and field-level permissions
This chapter assumes you can create permission sets in Setup and read basic SOQL. It also assumes you have the dedicated integration user and its minimal profile from the earlier chapters. Here you decide which objects and fields the integration can touch.
Two layers, checked in order
Salesforce checks object permissions first and field permissions second. Sharing, covered in the next chapter, then decides which records are visible.
Object permissions
Each object has up to six flags:
| Flag | Meaning |
|---|---|
| Read | See records the user has access to |
| Create | Insert new records |
| Edit | Update records the user has access to |
| Delete | Delete records the user has access to |
| View All Records | Read every record of the object, ignoring sharing |
| Modify All Records | Read, edit, and delete every record, ignoring sharing |
Grant only the flags the integration uses. A job that reads accounts needs Read and nothing else. View All and Modify All bypass the sharing model, so treat them as a last resort. The same goes for the org-wide "View All Data" and "Modify All Data" system permissions.
Field permissions
Field-level security (FLS) has two flags: readable and editable. Editable without readable is not meaningful, because the field would be hidden. A user needs object access before a field permission has any effect.
Some fields cannot be restricted, such as required fields and the record Name. Everything else defaults to no access unless a profile or permission set grants it. That default works in your favor, because you list the fields you want and the rest stay hidden.
A read-only permission set
This permission set from the plan grants API access, read on Account, and read on 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>Setting every unused flag to false keeps the intent explicit when someone reviews the file later. If the integration needs more fields, add one fieldPermissions block per field. Do not switch to a broad grant to save time.
Check what was granted
Query the permission records directly rather than trusting the Setup screens. This query shows the object flags for the permission set:
SELECT SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE Parent.Name = 'Integration_Account_Read'Look for any true in Delete, View All, or Modify All that the integration does not need. To check fields, query FieldPermissions in the same way:
SELECT Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE Parent.Name = 'Integration_Account_Read'
AND SobjectType = 'Account'Common mistakes
- Granting access through the profile. The profile is shared by every user who holds it. Keep it minimal and put real access in the permission set.
- Granting Edit when only Read is needed. Integrations that sync data one way rarely need write access.
- Forgetting fields. A field with no permission is missing from query results, and writing to it fails. Check the integration's field list against the permission set.
- Using View All Records to fix a missing-record problem. First check whether sharing is the cause. A narrower fix usually exists.
Exercise
The integration reads Opportunity records but also needs to update the StageName field. Which object flags and field flags does the permission set need, and which flags should stay off?
Show answer
Object: Read and Edit on Opportunity. Field: StageName readable and editable, plus readable on any other fields the integration reads. Keep Create, Delete, View All Records, and Modify All Records off, and do not grant editable on fields the integration only reads.