Sub topic 17
Designing and auditing FLS with least privilege
This chapter assumes you can set field access in Setup, you know the difference between profiles, permission sets, and permission set groups, and you can read basic Apex and SOQL. It covers how to decide who gets which field, how to package that access, and how to check afterward that the org matches your design.
What least privilege means for fields
Least privilege means each user gets the minimum field access their job requires, and nothing more. For field-level security (FLS), that has three consequences:
- A new field starts hidden. You grant access on purpose.
- Read is the default grant. Edit is granted only to people who change the value.
- Access follows a job function, not a person.
FLS is additive. If a user has Read through a profile and Edit through a permission set, the user gets Edit. Nothing in a profile or permission set can subtract access, except muting permission sets inside a permission set group. This is why least privilege depends on a restrictive starting point. You cannot fix an over-permissive profile by adding more permission sets.
Start from a minimal baseline
Make the baseline as small as you can, then add access with permission sets.
- Put users on a minimal profile, such as Minimum Access - Salesforce. It grants almost no object or field access.
- Create one permission set for each capability, for example "Account Notes Access" or "Revenue Fields Read". Do not create one per person.
- Grant Read only unless users must edit the field.
- Bundle permission sets into permission set groups that match job roles.
The key habit is to name permission sets after what they allow, not after who holds them. A set called "Account Revenue Read" tells an auditor what it does. A set called "Dana's Access" does not.
Design with a field inventory
Before you create anything, list the fields that need protection and decide who needs each one. A short table is enough.
| Field | Sensitivity | Read | Edit |
|---|---|---|---|
| Account.Name | Low | Everyone | Sales, Support |
| Account.AnnualRevenue | Medium | Sales, Finance | Finance |
| Account.Internal_Notes__c | High | Support managers | Support managers |
Rank fields by sensitivity and protect the high ones first. Fields that hold personal, financial, or contractual data are the usual candidates. Low-sensitivity fields such as Name can use broad access, because tracking them costs more than it protects.
Remember what Read and Edit actually do. Edit implies Read, so you never grant Edit alone. Also remember that object permission comes first: if a user lacks Read on Account, field access on Account fields has no effect.
Organize access with permission set groups
A permission set group combines several permission sets into one assignable unit. You assign a group such as "Support Manager" to a user, and the group carries every permission set that role needs. When the role changes, you edit the group once.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSetGroup xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Field and object access for support managers</description>
<label>Support Manager</label>
<permissionSets>Account_Notes_Access</permissionSets>
<permissionSets>Account_Revenue_Read</permissionSets>
<status>Updated</status>
</PermissionSetGroup>A group can also include a muting permission set. Muting removes specific permissions that the group's other permission sets would grant. It is useful when a shared permission set is almost right for a role and you need to take one field away. Muting applies only inside that group. If the same user gets the field through a profile or a permission set outside the group, the user still has access. Check the user's whole set of assignments, not just the group.
The group's status also matters. After you change a member permission set, the group recalculates. While status is Updating, assignments may not reflect the latest change, so wait for Updated before you test or audit.
A design flow
The following diagram shows the order of decisions.
Audit what exists
Setup shows access one permission set at a time, which is slow for an org-wide review. The FieldPermissions object lets you ask a field-centered question: who can see this field, and through which permission set or profile?
List<FieldPermissions> grants = [
SELECT Parent.Label, Parent.IsOwnedByProfile, Parent.Profile.Name,
PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE Field = 'Account.Internal_Notes__c'
ORDER BY Parent.Label
];
for (FieldPermissions fp : grants) {
String source = fp.Parent.IsOwnedByProfile
? 'Profile: ' + fp.Parent.Profile.Name
: 'Permission set: ' + fp.Parent.Label;
System.debug(source + ' read=' + fp.PermissionsRead + ' edit=' + fp.PermissionsEdit);
}Every profile has a hidden permission set that stores its field grants. That is why Parent.IsOwnedByProfile is in the query: it separates profile grants from true permission sets. Run this for each high-sensitivity field and compare the results with your inventory table. Any grant you cannot explain is a finding.
To go from a user to the fields they hold, query PermissionSetAssignment for that user's permission set IDs and filter FieldPermissions by ParentId. Do this when someone asks "why can this person see that field?"
Common problems an audit finds
- Edit granted where Read was enough. Users hold Edit because a permission set was copied from a bigger role.
- Broad profile grants. An old profile still gives Read on a sensitive field to hundreds of users, so every permission set you add on top is irrelevant.
- Access granted by an object-level shortcut. Permission sets can include "View All Fields" on an object, which gives Read on every field of that object, including ones added later. Review it like any wide grant.
- Orphaned permission sets. Sets with no assignments, or with access to fields that no longer exist, add clutter and hide real problems.
- Code that bypasses FLS. FLS configuration controls only what the platform enforces. Apex running in system mode can still read a hidden field. Review the classes that touch sensitive fields as part of the same audit.
Keep the design verifiable
Treat FLS as code. Keep permission sets and groups in source control as metadata, and deploy them through the same pipeline as your classes. A reviewer can then read a pull request and see exactly which field gained Read or Edit. Pair each sensitive field with a test like the one in the testing chapter, using System.runAs and a user assigned the relevant permission set, so a later change that exposes the field fails the build.
Summary of practices
- Start users on a minimal profile and add access through permission sets.
- Grant Read by default and Edit only where users change the value.
- Name permission sets after capabilities and bundle them into groups by role.
- Use muting sparingly, and remember it works only inside its group.
- Audit with
FieldPermissions, and review Apex for system-mode access to the same fields. - Store access as metadata and test it with
System.runAs.
Exercise
A user is in the "Support Manager" permission set group, which mutes Edit on Account.AnnualRevenue. The user's profile still grants Edit on that field. Can the user edit it? How would you find out where the access comes from?
Show answer
Yes, the user can still edit it. Muting applies only to permission sets inside the group, and the profile's grant is outside the group. To find the source, query FieldPermissions with Field = 'Account.AnnualRevenue' and PermissionsEdit = true, and look at Parent.IsOwnedByProfile and Parent.Profile.Name. Then remove Edit from the profile, or move the user to a minimal profile.
Exercise
Why is Read the safer default grant, and why is Edit never granted without Read?
Show answer
Read exposes the value but cannot change data, so a mistaken grant has a smaller effect than a mistaken Edit grant. Edit implies Read because a user cannot meaningfully change a value they cannot see, so Salesforce treats Edit as including Read.