Sub topic 9
Putting it together: working out who can see a record
This chapter assumes you know what object permissions, record ownership, org-wide defaults (OWD) and the role hierarchy are. Here you combine them to predict whether a given user can see or edit a given record.
The working model
Access to a record is the most permissive result of several independent grants. Nothing in the sharing model removes access that another mechanism has granted. Check the layers in this order:
- Object permission. Does the user's profile or a permission set grant Read (or Edit, Delete) on the object? If not, stop. The user gets no access, whatever the sharing says.
- Ownership. The owner of a record has full access to it, subject to object permissions.
- Org-wide default. If the OWD is Public Read Only or Public Read/Write, every user with the object permission gets that level on every record.
- Role hierarchy. If the OWD is Private or Public Read Only, users above the owner in the role hierarchy get access to the owner's records. This applies only when Grant Access Using Hierarchies is enabled for the object.
- Other grants. Sharing rules, teams and manual shares add access on top.
Worked example
Account has OWD Private. The roles are VP Sales, with a Sales Manager below it, and a Sales Rep below the manager. A second rep, Rep B, reports to a different manager in another branch. Ana is the Sales Rep and owns Account Acme. Every user has Read on Account through a profile.
| User | Relationship to Acme | Can read Acme? | Why |
|---|---|---|---|
| Ana | Owner | Yes | Ownership |
| Her Sales Manager | Above Ana | Yes | Role hierarchy |
| VP Sales | Above Ana | Yes | Role hierarchy |
| Rep B | Peer in another branch | No | Private OWD, not above Ana |
| Ana's peer under the same manager | Same level | No | Hierarchy flows up, not sideways |
If you change the OWD to Public Read Only, Rep B and Ana's peer can read Acme. They still cannot edit it.
Edit access follows the same logic
Edit works the same way, but each layer grants its own level. OWD Public Read Only gives read to everyone. Edit still comes from ownership, the hierarchy above the owner, or a sharing grant. The user also needs Edit on the object. A manager above the owner who has only Read on the object can see the record but not change it.
Checking your prediction
Compare your prediction with what Salesforce reports. This query returns the effective access for one user and one record:
SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess
FROM UserRecordAccess
WHERE UserId = '005XXXXXXXXXXXXXXX'
AND RecordId = '001XXXXXXXXXXXXXXX'Exercise
Contact has OWD Private. Maria owns a contact. Her role is under Team Lead Raj, who is under Director Lee. Sam is a peer of Maria under Raj. All four users have Read and Edit on Contact, and Grant Access Using Hierarchies is on. Who can edit Maria's contact?
Show answer
Maria (owner), Raj and Lee (above her in the hierarchy). Sam cannot, because access flows upward only and there is no sharing rule, team or manual share giving him access.