Sub topic 7
Permissions grant object access; sharing grants record access
This chapter assumes you know what profiles and permission sets are, and that you have seen org-wide defaults (OWD) and roles in Setup. Here you will learn how object permissions and record sharing combine. Mixing them up is the most common reason a user "has the permission but still can't see the record".
Two separate questions
Salesforce answers two questions in order when a user touches data:
- Object-level: may this user work with this type of record at all? Profiles and permission sets answer this with Create, Read, Edit, Delete, View All, and Modify All.
- Record-level: may this user work with this specific record? The sharing model answers this with ownership, OWD, the role hierarchy, sharing rules, teams, and manual shares.
Access to a record requires a "yes" from both. Field-level security then decides which fields of that record the user sees.
What each layer controls
| Aspect | Object permissions | Record sharing |
|---|---|---|
| Question answered | Can the user work with this object? | Can the user work with this record? |
| Configured through | Profiles, permission sets, permission set groups | OWD, roles, sharing rules, teams, manual shares |
| Granularity | Whole object | Single record |
| Direction | Adds access (permission sets) or sets baseline (profile) | Opens access beyond the OWD baseline |
| Can restrict | Yes, by omitting a permission | Only down to the OWD; sharing only opens access |
How sharing opens record access
The OWD sets the most restrictive baseline for an object. Typical values are Private, Public Read Only, Public Read/Write, and Controlled by Parent. Everything else in the sharing model opens access beyond that baseline:
- Ownership: the record owner can see and edit the record, subject to object permissions.
- Role hierarchy: users above the owner in the hierarchy inherit access when "Grant Access Using Hierarchies" is on for the object.
- Sharing rules: criteria-based or owner-based rules share records with roles, groups, or public groups.
- Teams: account teams, opportunity teams, and case teams add members to individual records.
- Manual sharing: a user with sufficient access shares one record with another user or group.
None of these can take away access that the OWD already provides.
The two layers intersect
The effective access is the more restrictive result of the two layers. Three cases show this:
- A user has Edit on Opportunity through a permission set, but the OWD is Public Read Only and the user owns none of the records. The user can read all opportunities and edit none of them.
- A sharing rule gives a user Read/Write on Accounts, but their only access to Account comes from a profile with Read. The user gets Read. Sharing cannot raise access above the object permission.
- A user owns a record, but Delete is not enabled on the object. The user cannot delete it. Ownership does not override the missing permission.
View All and Modify All bypass sharing
Two object permissions skip the record-level check for one object:
- View All gives Read access to every record of the object, regardless of OWD and sharing.
- Modify All gives Read, Edit, Delete, and Transfer on every record of the object. (It also grants Approve in approval processes.)
Two system permissions do the same for the whole org:
- View All Data
- Modify All Data
These are broad grants. A permission set that adds "View All" on Account to fix a single missing record exposes every account to every assignee. Prefer a sharing rule or manual share when only some records are needed.
Here is the full picture, from narrowest to broadest:
| Grant | Scope | Bypasses sharing? |
|---|---|---|
| Read on an object | All records the sharing model exposes | No |
| View All on an object | All records of that object | Yes, for reads |
| Modify All on an object | All records of that object | Yes, for read and write |
| View All Data | All objects | Yes, for reads |
| Modify All Data | All objects | Yes, for read and write |
Apex: sharing mode is not permission enforcement
Apex has the same split, and the keywords are easy to confuse:
with sharingmakes the class respect the running user's record-level access.without sharingignores record-level sharing.- Neither keyword enforces object permissions or field-level security. By default, Apex runs in system mode for CRUD and FLS.
To enforce the permissions of the running user, use user mode in the query itself:
public with sharing class AccountReader {
public static List<Account> visibleAccounts() {
// with sharing: only records the user can reach through sharing
// WITH USER_MODE: enforces the user's object permissions and field-level security
return [
SELECT Id, Name, AnnualRevenue
FROM Account
WITH USER_MODE
ORDER BY Name
LIMIT 50
];
}
}If the user lacks Read on Account or on AnnualRevenue, the query throws a QueryException. If the user has both permissions but sharing hides some accounts, those rows are missing from the result and no error is thrown. The two failure modes look different, and that difference helps you diagnose problems.
Common errors
- Granting Read on an object and expecting all records to appear. With a Private OWD, the user sees only what sharing exposes.
- Granting Edit and expecting every record to be editable. Edit applies only to records the user can already reach with edit-level sharing.
- "Fixing" a sharing problem with View All or Modify All. This works, but it removes the record-level boundary for that object.
- Assuming
with sharingenforces field-level security. It does not. - Forgetting that Controlled by Parent objects, such as Contacts under a Private Account OWD with certain settings, inherit access from the parent record.
Diagnosing a missing record
Work through the layers in order:
- Confirm the user has Read on the object, from the profile or any assigned permission set.
- Check the OWD for the object. If it is Public Read Only or more open, sharing is probably not the cause.
- On the record, use Sharing, then Expand List, to see who has access and why. Look for ownership, role hierarchy, rule, team, or manual entries for the user.
- Check whether the record is hidden by sharing, not by field-level security. A visible record with an empty-looking field points at FLS, not at sharing.
- If access is needed for a small set of records, add a sharing rule or a manual share before considering View All or Modify All.
Exercise
A user is assigned a permission set that grants Read, Create, Edit, and Delete on Opportunity. The Opportunity OWD is Private, and the user is not in the owner's role hierarchy line. The user reports they cannot find a colleague's opportunity. Which layer is the cause, and what are two ways to fix it with different scope?
Show answer
The record-level layer is the cause. The object permissions are fine, but with a Private OWD the user sees only their own opportunities and those exposed by sharing. A narrow fix is a sharing rule, an opportunity team entry, or a manual share for that record. A broad fix is adding View All on Opportunity (or View All Data), which exposes every opportunity to the user and should be used only when that is intended.