Sub topic 9
Putting it together: working out who can see a record
This chapter assumes you know the pieces from earlier chapters: object permissions on profiles and permission sets, record ownership, org-wide defaults (OWD), roles, and the role hierarchy. Here you combine them into one procedure that predicts whether a user can read or edit a given record.
Two questions, asked in order
Salesforce answers two separate questions, and a user needs a "yes" to both.
- Object access: Does the user's profile or a permission set grant Read, Create, Edit or Delete on this object?
- Record access: Does the user have access to this specific record, and at what level?
Object permissions set the ceiling for what a user may do with the object. Record access decides which rows the user can do it to. A user with Edit on Opportunity who can only read a particular opportunity cannot edit it. A user who has record-level Edit access through sharing but no object Edit permission also cannot edit it. The effective access is the lower of the two.
The sources of record access
For a given user and record, access can come from any of these sources. Salesforce takes the most permissive result.
| Source | What it grants |
|---|---|
| Ownership | Full access to records the user owns, within object permissions |
| Org-wide default | The baseline level for every user who is not the owner |
| Role hierarchy | Access to records owned by users in roles below, at the level the subordinate has |
| Sharing rules | Extra Read Only or Read/Write access for defined groups of users |
| Teams and manual sharing | Access to individual records, such as account teams and the Sharing button |
| View All / Modify All | Access to every record of an object, ignoring sharing |
The last row works differently from the others. It is an object permission that bypasses record sharing entirely, which later chapters cover.
A procedure you can follow
Use these steps in order.
- Check object permissions. If the user lacks Read on the object, stop: no access. Note whether they have Edit and Delete.
- Check View All or Modify All on the object. These also exist as "View All Data" and "Modify All Data" system permissions. If present, the user can see (or edit) every record.
- Check ownership. The owner can see and edit the record, within object permissions.
- Read the OWD. If it is Public Read Only or Public Read/Write, everyone with object Read already has at least that level. If it is Private, continue.
- Check the role hierarchy. Is the owner in a role below the user's role? If so, and Grant Access Using Hierarchies applies to the object, the user gets access.
- Check the opening mechanisms: sharing rules, account or opportunity teams, manual shares, and access inherited from a parent record.
- Take the highest level found, then cap it by the object permissions from step 1.
Worked example
Take a company with this role hierarchy and the Opportunity OWD set to Private.
- VP Sales (Vera)
- Sales Manager East (Marcus)
- Rep East 1 (Ana), who owns opportunity OPP-1
- Rep East 2 (Ben), who owns opportunity OPP-2
- Sales Manager West (Wen)
- Rep West 1 (Carla), who owns opportunity OPP-3
Every user has a profile with Read, Create and Edit on Opportunity. None has View All or Modify All.
| User | OPP-1 (Ana) | OPP-2 (Ben) | OPP-3 (Carla) | Why |
|---|---|---|---|---|
| Ana | Read, Edit | None | None | Owner of OPP-1. A peer's record is invisible under Private. |
| Ben | None | Read, Edit | None | Same reasoning. Peers do not share with each other. |
| Marcus | Read, Edit | Read, Edit | None | Both reps are below him. Carla is in a different branch. |
| Wen | None | None | Read, Edit | Only Carla is below him. |
| Vera | Read, Edit | Read, Edit | Read, Edit | Everyone is below her in the hierarchy. |
Now change the OWD to Public Read Only. Every user can read all three opportunities. Edit access does not change: Ana still edits only OPP-1, Marcus edits OPP-1 and OPP-2, and so on. Changing the OWD to Public Read/Write lets everyone edit every opportunity. Delete stays with the owner and the users above the owner in the hierarchy, and it still needs the object Delete permission.
Common errors
- Expecting access to flow sideways or down. The hierarchy opens access upward only. Marcus sees Ana's records, but Ana does not see Marcus's.
- Treating the role hierarchy as a reporting line. A role is a position for sharing purposes. Two people can report to the same manager and still sit in unrelated roles, and a user's manager field does not grant any record access.
- Confusing roles with profiles. The profile controls object and field permissions. The role controls record visibility. Changing someone's role never gives them Edit on an object.
- Forgetting the object permission. A Public Read/Write OWD does nothing for a user whose profile has no Read on the object.
- Assuming hierarchy access always applies. For custom objects, the Grant Access Using Hierarchies checkbox can be turned off, which removes the upward flow for that object. Standard objects always use the hierarchy.
- Forgetting the owner is part of the calculation. When ownership changes, access that came from the old owner's position in the hierarchy goes with them. The new owner's superiors now gain access.
- Assuming one object's OWD applies to related objects. Some child objects, such as Contact under Account when set to "Controlled by Parent", inherit access from the parent. Others have independent settings. Check each object separately.
Checking your prediction
After you predict an outcome, verify it. The UserRecordAccess object reports a user's resulting access after all sharing mechanisms are applied.
SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess
FROM UserRecordAccess
WHERE UserId = '005XXXXXXXXXXXXXXX'
AND RecordId = '001XXXXXXXXXXXXXXX'Replace the placeholders with a real user Id and record Id. Run this for each cell in the table above and compare the results with your prediction. If a result disagrees, the cause is usually a source you did not account for, such as a sharing rule, a team membership or a View All permission.
To see which mechanism produced the access, query the share table for the object. For accounts, the RowCause column names the reason.
SELECT Id, AccountId, UserOrGroupId, AccountAccessLevel, RowCause
FROM AccountShare
WHERE AccountId = '001XXXXXXXXXXXXXXX'Rows with the cause Owner, Team or Manual map directly to steps in the procedure. Hierarchy access does not appear as a row for each superior, because it is calculated from the role structure and not stored per user. An absent row for a manager therefore does not mean the manager lacks access.
Edge cases to keep in mind
- Multiple sources at different levels. If the hierarchy gives Read and a sharing rule gives Read/Write, the user gets Read/Write.
- Field-level security still applies. Record access lets a user open the record. Field permissions still hide individual fields.
- Sharing is recalculated when inputs change. Moving a user to another role, changing an OWD or changing a record's owner triggers recalculation. For large orgs it can take time, so changes may not appear instantly.
- The OWD sets the floor. If you want a user to have less access to a record than the default allows, you cannot do it with sharing. You must tighten the OWD and then open access where needed.
Exercise
The Case OWD is Private. Priya is a support agent and owns case C-100. Her manager Tomas sits in a role directly above hers. Dev is another agent in a role at the same level as Priya. Dev's profile has Read and Edit on Case, Tomas's profile has Read only on Case, and nobody has View All or Modify All. What access do Tomas and Dev have to C-100?
Show answer
Dev has no access. The OWD is Private, Dev does not own the case, and a peer's role gives nothing, so object permissions alone do not help. Tomas gets record-level access through the hierarchy because Priya sits below him, but his profile has only Read on Case, so his effective access is Read. The lower of object permission and record access wins.