Sub topic 4
Field-level security: Read and Edit on individual fields
This chapter assumes you know how profiles grant object permissions (Read, Create, Edit, Delete) and that you can find an object's fields in Setup. Object access decides whether a user can work with a record type of data at all. Field-level security (FLS) decides which fields on that object the user can see or change.
What FLS controls
FLS has two settings per field:
- Read: the user can see the field's value.
- Edit: the user can change the value. Edit requires Read, so you cannot grant Edit alone.
FLS applies to page layouts, list views, reports, search results, the API, and Apex that respects user mode. A field hidden by FLS is hidden everywhere, even if a page layout includes it.
How FLS combines with object permissions
A user needs both layers. Object permissions come first, and FLS narrows access within the object.
| Object permission | Field permission | Result |
|---|---|---|
| Read | Read only | User sees the value and cannot change it |
| Read, Edit | Read and Edit | User can see and change the value |
| Read, Edit | No Read | Field is invisible to the user |
| No Read | Read and Edit | No access, because the object is not available |
Where you set FLS
You can set FLS in two places, and the results add together.
- Profile: the baseline for every user with that profile.
- Permission set: extra access for selected users.
If a profile grants Read on a field and a permission set grants Edit, the user gets Edit. Permissions are additive, so a permission set can raise access but cannot lower what the profile grants. To remove access inside a permission set group, you use a muting permission set, which a later chapter covers.
In Metadata API format, a permission set stores FLS in fieldPermissions elements:
<?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>Here readable maps to Read and editable maps to Edit. This permission set gives read-only access to Account.AnnualRevenue.
Common errors
- Field missing from a layout or report. The user lacks Read. Check FLS before you edit the page layout.
- Field shows but cannot be edited. The user has Read without Edit, or the field is read-only by nature, such as a formula or auto-number field. FLS cannot make those editable.
- New field invisible to everyone. A new custom field gets no access by default for most profiles. You choose who gets access when you create it, or you grant it afterward.
- Required fields. A field marked required in the field definition or as a universally required field cannot have FLS removed. Layout-only required fields can be hidden by FLS, which can break record creation, so test it.
- Mixing up FLS and layouts. A layout controls placement and layout-level read-only status. It never grants access that FLS denies.
Exercise
A user's profile grants Read on Account.AnnualRevenue and their object permission on Account is Read only. You assign a permission set that grants Edit on Account.AnnualRevenue. Can the user edit the field on an existing account? Explain.
Show answer
No. Field Edit does not override the object permission. Because the user lacks Edit on the Account object, they cannot edit any Account record, including that field. The permission set would also need to grant Edit on the Account object.