Sub topic 4
Field-level security: Read and Edit on individual fields
Field-level security (FLS) controls whether a user can see or change a single field on an object. This chapter assumes you know what a profile and a permission set are, and that you have read the previous chapter on object permissions. You should also be comfortable opening an object's field definitions in Setup.
What field-level security does
Object permissions decide whether a user can work with an object at all. FLS narrows that down to individual fields. Each field gets two settings for each profile or permission set:
- Read: the user can see the field's value.
- Edit: the user can change the field's value. Edit always includes Read.
If a user has neither, the field is hidden. It does not appear on record pages, in list views, in reports, or in search results.
FLS is a permission, so it applies wherever the user touches data. This includes page layouts, the API, reports, list views, and Lightning components that respect FLS.
How FLS combines with object permissions
A field can only be as accessible as its object allows. FLS cannot grant access to an object the user cannot read.
| Object permission | Field setting | Result |
|---|---|---|
| No Read on object | Read and Edit on field | No access. The user cannot reach the object. |
| Read on object | Read on field | User sees the value but cannot change it. |
| Read and Edit on object | Read on field | User edits the record but this field is read-only. |
| Read and Edit on object | Read and Edit on field | User can change the value. |
| Read and Edit on object | No access on field | The field is hidden from the user. |
The rule of thumb is that the most restrictive of the object permission and the field setting wins for that field.
Where you set FLS
FLS lives on both profiles and permission sets. Because permission sets are additive, the effective setting for a field is the most permissive across the user's profile and all assigned permission sets. If the profile grants Read and a permission set grants Edit, the user gets Edit.
You can configure FLS in several places:
- On the field. In Object Manager, open the field and choose Set Field-Level Security. You see a grid of profiles with Visible and Read-Only checkboxes. This is convenient when you create a new field.
- On the profile. Open the profile, go to Object Settings, choose the object, and edit the field permissions.
- On a permission set. Open the permission set, go to Object Settings, choose the object, and edit the field permissions.
In the field-level grid, "Visible" means Read, and unchecking "Read-Only" while Visible is checked means Edit.
FLS in Metadata API format
In metadata, FLS appears as fieldPermissions elements. This permission set gives read-only access to Annual Revenue on Account, along with Read on the Account object:
<?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>Each fieldPermissions element has three parts:
field: the object and field API name, in the formObject.Field.readable: whether the user can see the field.editable: whether the user can change it.
Setting editable to true while readable is false is invalid. Edit implies Read.
Fields without a configurable FLS
Not every field has FLS settings. Some cases behave differently:
- Required fields. A field that is required at the database level, or marked required when you create it, is always visible and editable to anyone who can edit the object. You cannot hide it with FLS. Fields that are only required on the page layout are different. FLS can still hide them, and then the layout requirement does not apply.
- Name fields. The Name field on most objects is always readable.
- System fields. Fields such as
CreatedDateandLastModifiedByIdare read-only, and FLS cannot make them editable. - Formula and roll-up summary fields. These can be hidden with Read but never have Edit, because they are calculated.
- Master-detail relationship fields. The relationship field on the detail record is required, so it behaves like a required field.
A common surprise is making a field required at creation time and then wondering why FLS settings are missing. The field is simply always available.
Where FLS applies and where it does not
FLS is enforced in the user interface, reports, list views, search, and the REST and SOAP APIs. Apex is different.
By default, Apex runs in system mode. This means it ignores the running user's object permissions and FLS. If a controller queries Account.AnnualRevenue and returns it to a Lightning component, a user without Read on the field can still see the value.
To enforce FLS in Apex, use one of these approaches:
WITH USER_MODEin SOQL, which enforces object permissions and FLS (and sharing).WITH SECURITY_ENFORCED, an older clause that throws an exception if the user lacks access to any queried field.Security.stripInaccessible(), which removes inaccessible fields from the records instead of throwing.as useron DML operations, for exampleinsert as user acc;.
List<Account> accounts = [
SELECT Name, AnnualRevenue
FROM Account
WITH USER_MODE
LIMIT 10
];If the running user lacks Read on AnnualRevenue, this query throws a QueryException. Use Security.stripInaccessible when you want to return partial data instead of failing.
Page layouts versus FLS
A page layout controls where a field appears. FLS controls whether the user may see it at all. The two work together:
- If a field is on the layout but FLS hides it, the user does not see it.
- If a field is not on the layout but FLS grants Read, the user does not see it on the record page. It can still appear in reports, list views, and API responses.
Removing a field from a layout is therefore not a security control. Use FLS for access, and layouts for presentation.
Common mistakes
- Granting Edit on the field but not on the object. The field stays read-only because object Edit is missing.
- Using layouts to hide sensitive data. The data remains reachable through reports and the API.
- Forgetting the profile. A permission set adds access, but it cannot remove access that the profile grants. To remove access, you must change the profile or use a muting permission set inside a permission set group, which later chapters cover.
- Expecting FLS to control which records a user sees. It does not. Record access comes from sharing, covered in a later chapter.
- Assuming Apex respects FLS. It does not unless you enforce it.
Auditing FLS
To see which profiles and permission sets grant a field, query the FieldPermissions object:
SELECT Parent.Name, Parent.Label, Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE SobjectType = 'Account' AND Field = 'Account.AnnualRevenue'The Parent is a permission set. Profiles appear here too, as permission sets with Parent.IsOwnedByProfile set to true. Add AND Parent.IsOwnedByProfile = false to list only standalone permission sets.
In Setup, the Field Accessibility feature has been retired in newer orgs, so the SOQL query is the most reliable way to audit a field across the whole org.
Exercise
A user's profile gives Read on Account.AnnualRevenue and no Edit. You assign a permission set that gives Edit on the field but gives the Account object only Read. Can the user change the field on an Account record? Explain why.
Show answer
No. Edit on a field only takes effect when the user also has Edit on the object. The permission set adds field Edit, but the user's object permission is still Read-only, so the field stays read-only. To fix it, grant Edit on the Account object as well, in the profile or a permission set.
Exercise
You remove a sensitive field from the page layout so sales users no longer see it. A sales user still sees the value in a report. Why, and what should you change?
Show answer
A page layout only controls presentation on the record page. FLS controls access. Because the user's profile or permission sets still grant Read on the field, reports can show it. Remove Read on the field from the profile and from any permission set that grants it, or place the user in a permission set group that mutes it.