Sub topic 2
Profiles and permission sets: the containers for access
This chapter assumes you can navigate Setup and the Object Manager. It also assumes you know what objects, fields, and users are, and can read basic SOQL. Field-level security (FLS) settings are stored inside profiles and permission sets, so you need to understand these containers before you can set or debug field access.
What a container is
A user never has field access directly. Access is granted through a container that is assigned to the user. Salesforce has two kinds:
- A profile is a container of settings that every user must have. Each user has exactly one profile.
- A permission set is an optional container of settings that you assign on top of the profile. A user can have many permission sets.
Both containers can hold object permissions (create, read, edit, delete) and field permissions (read, edit). Field permissions are the FLS settings this tutorial is about.
How access combines
Access is additive. The system takes the profile and all assigned permission sets, and a user gets the most permissive result for each setting. If the profile gives no access to Account.AnnualRevenue and one permission set gives Read, the user can read it.
A permission set can only grant access. It cannot take access away from the profile. If you need to subtract access, you must remove it from the profile or from the permission set that grants it. Permission set groups, covered in a later chapter, add a "muting" feature for this purpose.
Profile versus permission set
| Aspect | Profile | Permission set |
|---|---|---|
| Assigned per user | Exactly one | Zero or more |
| Can be omitted | No | Yes |
| Can grant object and field access | Yes | Yes |
| Can restrict access below another container | No (it is the baseline) | No (grants only) |
| Holds login hours and login IP ranges | Yes | No |
| Holds page layout assignments | Yes | No |
| Reusable across roles | Poorly, one per user | Well, mix and match |
Page layout assignments and login restrictions are why a profile is still required. Everything else about data access can live in permission sets.
Why many teams prefer permission sets
Profiles tend to multiply. Suppose Sales and Support users need the same base access, but a few Sales users also need to edit Internal_Notes__c. With profiles only, you clone the Sales profile and maintain two near-identical copies. Every later change must be made twice, and the copies drift apart.
With permission sets, you keep one small baseline profile and put each job-specific grant into its own permission set. The grant for Internal_Notes__c becomes one permission set named for what it does. You assign it to the users who need it and remove it when they no longer do.
Salesforce recommends this permission-set-led approach. A common baseline is the Minimum Access - Salesforce profile, which grants almost nothing, so that every real permission comes from a named permission set.
A profile is also a permission set underneath
Internally, Salesforce stores a profile's permissions in a hidden permission set that is owned by the profile. You can see this when you query the data. The PermissionSet object has an IsOwnedByProfile field, and the FieldPermissions object stores FLS rows for both profiles and permission sets in one place.
This query lists every container that grants access to one field. Run it in Anonymous Apex in a sandbox or developer org:
for (FieldPermissions fp : [
SELECT Parent.Label, Parent.IsOwnedByProfile, Parent.Profile.Name,
PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE SobjectType = 'Account'
AND Field = 'Account.AnnualRevenue'
]) {
String owner = fp.Parent.IsOwnedByProfile
? 'Profile: ' + fp.Parent.Profile.Name
: 'Permission set: ' + fp.Parent.Label;
System.debug(owner + ' | read=' + fp.PermissionsRead
+ ' | edit=' + fp.PermissionsEdit);
}Each debug line names a container and shows its Read and Edit flags. Note that this query reads the settings stored in containers. It does not tell you what one user can do. For that, you also need that user's assignments:
for (PermissionSetAssignment psa : [
SELECT PermissionSet.Name, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = :UserInfo.getUserId()
]) {
System.debug(psa.PermissionSet.Name
+ ' (profile-owned: ' + psa.PermissionSet.IsOwnedByProfile + ')');
}The result includes the user's profile as a profile-owned row, followed by any permission sets.
Licenses limit what a container can hold
A container cannot grant everything. Each user has a user license, and each profile is tied to one license. A profile or permission set can only include permissions that its license allows. For example, a permission set created for a Salesforce license cannot be assigned to a user whose license does not support its contents.
Some permission sets are tied to a permission set license, which unlocks a feature that the user license does not include. If assigning a permission set fails, a license mismatch is the first thing to check.
Common errors
- Granting in the wrong place. An admin adds Edit on a field to a permission set, but the user still cannot see it. The cause is often that the permission set was never assigned, or was assigned to a different user. Check the assignment first.
- Forgetting object access. FLS applies to fields within an object the user can already access. If the object permission is missing, the field setting has no visible effect. The next chapter covers this order.
- Expecting a permission set to remove access. If a user can still see a field after you changed one container, another container still grants it. Look at every assigned container.
- Editing a profile that many users share. A change to a profile applies to every user who has it. Make a targeted change through a permission set when only some users need it.
- Forgetting that new fields start with no access for most users. When you create a custom field, you choose which profiles can see it. A field with no grants is invisible to non-administrators.
Where you set field access
In Setup, you can reach FLS from three places: the field's own page in the Object Manager, a profile's object settings, or a permission set's object settings. They all edit the same underlying FieldPermissions data. The next chapters cover object permissions and the Read and Edit flags in detail, then walk through the Setup steps.
Exercise
A user's profile has no access to Account.InternalNotes_c. The user is assigned two permission sets. One grants Read on that field. The other grants nothing on it. Can the user read the field, and can the user edit it? What would you change to give edit access without affecting other users?
Show answer
The user can read the field, because access is additive and the most permissive setting wins, so the permission set that grants Read applies. The user cannot edit it, because no container grants Edit. To give edit access without affecting other users, add Edit (which requires Read) on that field to a permission set, then assign that permission set only to this user, rather than changing the shared profile. Object edit access to Account is also required.
Exercise
Why can't a permission set be used to block a field that the user's profile already grants?
Show answer
A permission set can only add permissions. Effective access is the most permissive combination of the profile and all permission sets, so a permission set cannot lower what the profile gives. To block the field you must remove it from the profile (and from any other container that grants it), or use muting in a permission set group.