Sub topic 6
Object and field-level permissions
This chapter assumes you know how to create a permission set in Setup and how to read a SOQL query. It also assumes you have a dedicated integration user with an API-only license and a minimal profile, as set up in the previous chapters. Here you decide which objects the user can touch, which operations it can perform, and which fields it can see.
How the two layers fit together
Salesforce checks two layers of access before an API call returns data:
- Object permissions decide whether the user can read, create, edit, or delete records of an object. They also decide whether the user can bypass sharing for that object.
- Field-level security (FLS) decides, for each field, whether the user can read it and whether the user can edit it.
Both layers must allow the action. Read access on Account does not expose every Account field. A readable field is useless if the user has no Read permission on the object.
Sharing, covered in the next chapter, is a third layer. It decides which records of the object the user can reach.
Object permissions
Each object has these flags in a permission set:
| Flag | Metadata name | What it allows |
|---|---|---|
| Read | `allowRead` | Query and retrieve records the user can see through sharing |
| Create | `allowCreate` | Insert new records |
| Edit | `allowEdit` | Update records the user can see |
| Delete | `allowDelete` | Delete records the user can see |
| View All | `viewAllRecords` | Read all records of the object, ignoring sharing |
| Modify All | `modifyAllRecords` | Read, edit, and delete all records of the object, ignoring sharing |
Some of these flags depend on others. Edit and Delete require Read. Create requires Read. View All requires Read. Modify All requires View All, Read, Edit, and Delete, so granting it turns on all of those.
Start every object at Read only and add flags one at a time, based on the requirements you listed earlier. An integration that only pulls data into a warehouse needs Read and nothing else. An integration that upserts Contacts needs Read, Create, and Edit, and it does not need Delete.
View All and Modify All
View All and Modify All are the most common cause of silent over-privilege. They look like convenience flags, but they remove sharing as a limit on what the integration can see. A user with View All on Account can read every Account in the org, even if the sharing model is Private.
Grant them only when the integration really must see every record, for example a nightly full export. Even then, prefer View All over Modify All, and prefer these object-level flags over the system permissions View All Data and Modify All Data. The system permissions apply to every object in the org, including ones added after you set up the integration.
Field-level security
FLS has two flags per field:
- Read (
readable): the field can be queried and appears in API responses. - Edit (
editable): the field can be written. Edit requires Read.
FLS is granted per permission set, and it is separate from the object permission. If you grant Read on Account and set no field permissions in a profile or permission set, the user may see no custom fields on Account at all. With the permission set in this tutorial, the user can read Industry and the Account Name field.
Some fields are outside your control:
- Universally required fields, such as the Name field on Account, are always accessible and cannot be restricted by FLS.
- Formula, roll-up summary, and auto-number fields are never editable, regardless of the
editableflag. - System fields such as
Id,CreatedDate, andLastModifiedDateare not governed by FLS in the same way as custom data fields.
What happens when a field is not accessible
The API treats an inaccessible field differently depending on how you ask for it.
- A SOQL query that names a field the user cannot read fails with
INVALID_FIELD. The error says the field does not exist or is not accessible, which makes the two cases look the same. - A REST
GETof a single record by Id returns only the fields the user can read. The others are left out of the response. - A
POSTorPATCHthat includes a field the user cannot edit fails with an error such asINVALID_FIELD_FOR_INSERT_UPDATE, or the field is rejected. Check your own results against this behavior in the sandbox instead of relying on a single case.
This difference is why you test with the real queries your integration runs, not with a generic one.
A minimal permission set
The metadata below grants API access, Read on Account, and Read on one field. Nothing else is enabled.
<?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>Three details matter here:
- Every flag is written out, including the
falseones. Explicit values make the file easier to review and diff. ApiEnabledis a user permission, not an object permission. Without it, the user cannot call the API at all, whatever else it has.- This file grants nothing on any other object. Objects not listed are not accessible unless the profile or another permission set grants them.
Permissions are additive. Salesforce has no deny rule, so the user's effective access is the union of the profile and every assigned permission set. If the profile or another permission set grants Delete on Account, the false in this file does not take it away. This is why the profile must stay minimal.
Building the set from requirements
Take the requirement list from earlier in the tutorial and turn it into a grid before you write any metadata. For each object, mark the operations the integration performs, then list each field it reads or writes.
| Object | Operations | Fields read | Fields written |
|---|---|---|---|
| Account | Read | Name, Industry | None |
| Contact | Read, Create, Edit | Email, LastName | Email, LastName |
| Order | None | None | None |
Everything that does not appear in the grid stays off. When you add a field to the integration later, update the grid first and then the permission set. This keeps a written record you can compare against what the org actually grants.
Watch for indirect needs:
- A query that traverses a relationship, such as
Contact.Account.Name, needs Read on the related object and on the related field, not only on Contact. - Creating a record that has a required lookup needs Read on the parent object so that the Id can be validated.
- Writing to a master-detail child may be affected by the parent's sharing, even with the right object permission on the child.
Verifying object and field access
Do not trust the Setup UI alone. Query the permission records directly. The first query shows the object flags granted by one permission set, which 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'Field permissions live in the FieldPermissions object. This query lists every field the same permission set exposes:
SELECT Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE Parent.Name = 'Integration_Account_Read'Then test as the integration user, not as an admin. The login and query below confirm that the user reads what it should:
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file server.key \
--username [email protected] \
--instance-url https://test.salesforce.com \
--alias integration-sandbox
sf data query \
--target-org integration-sandbox \
--query "SELECT Id, Name, Industry FROM Account LIMIT 5"Run a second query that selects a field you did not grant, and a third against an object you did not grant. Both should fail. A test that only proves access works says nothing about over-privilege.
Common mistakes at this layer
- Cloning the standard Integration or admin profile. Profile-level object permissions often include more than the integration needs, and you cannot take them away in a permission set.
- Granting Modify All to fix a failing test. The failure is usually a missing field permission or a sharing restriction. Find the real cause first.
- Granting Edit on every readable field. Make fields writable only if the integration writes them.
- Forgetting new fields. A custom field added later has no FLS for your permission set. The integration will not see it until you add it, which is the safe default and also a common source of "it works for admins" bugs.
- Relying on page layouts. Layouts hide fields in the UI only. The API ignores them, and FLS is the control that applies.
Exercise
The integration user has a permission set with allowRead on Contact and readable on Contact.Email. A query for SELECT Id, Email, Phone FROM Contact fails with INVALID_FIELD. What is the likely cause, and how do you fix it without granting extra object permissions?
Show answer
The permission set has no field permission for Contact.Phone, so the user cannot read it, and the API reports it as an invalid or inaccessible field. Add a fieldPermissions entry with readable true and editable false for Contact.Phone, only if the integration actually needs that field. Do not add View All or Modify All, since they do not address field-level security.
Exercise
A profile grants Delete on Account. Your integration permission set sets allowDelete to false on Account. Can the integration user delete Accounts?
Show answer
Yes, if sharing lets it see the records. Permissions are additive and Salesforce has no deny rule, so the profile's Delete permission still applies. Remove Delete from the profile, or use a profile that grants nothing on Account, and grant access only through permission sets.