Sub topic 14
Finding out why a user can or cannot see a record
This chapter assumes you know org-wide defaults, the role hierarchy, sharing rules, manual sharing, and account teams from the earlier chapters. You should also know basic SOQL. The goal is a repeatable method for answering one question: why does this user have, or lack, access to this record?
Start with the layers, in order
Record access is the result of several independent checks. A user sees a record only if every layer that can block them allows it, and at least one layer that can grant access does so. Work through the layers in this order, because a failure at an early layer makes the later ones irrelevant.
- Object permission. The user's profile or permission sets must give Read on the object. Without it, no sharing setting matters.
- Record access. The user must own the record, or be granted access by org-wide defaults, the role hierarchy, a sharing rule, a team, or a manual share.
- Field-level security. The record can be visible while individual fields are hidden. A user who "can't see the amount" may be a field-level security problem and not a sharing problem.
Two permissions override record access entirely: View All and Modify All on an object, and the system permissions View All Data and Modify All Data. If the user has one of these, you can stop looking for share rows. They will not exist, because the access does not come from sharing.
Check the cheap facts first
Before you query anything, collect four facts. Each takes under a minute and resolves a large share of cases.
- The owner. Open the record and note the owner. If the owner is a queue, remember that queue members get access through the queue, not through ownership.
- The org-wide default for the object, under Setup, Sharing Settings. If it is Public Read Only or Public Read/Write, the user can already read every record, and a "cannot see" report points to the object permission or a different record.
- The user's role and the owner's role. The user gets hierarchy access only if their role is above the owner's, and only if Grant Access Using Hierarchies is checked for that object. Custom objects can have that box cleared.
- Group membership. Find which public groups, roles, and queues the user belongs to, because sharing rules target those.
Note that the hierarchy gives access to the owner's managers, not to people in a parallel branch of the same level. Two users with the same role do not see each other's private records unless a sharing rule or the default allows it.
Use the Sharing button and Sharing Hierarchy
The quickest tool for a single record is the Sharing button on the record detail page. It lists every user, group, role, and queue that has access, the access level, and the reason. Reasons are shown as text such as Owner, Role, Sharing Rule, Manual Sharing, or Account Team.
The button appears only for records where the viewing user is allowed to share. It is hidden when the default is Public Read/Write, because sharing adds nothing there.
For the opposite view, use Sharing Hierarchy or the Access Level Hierarchy option from the user's record. It shows who above the user in the hierarchy can see that user's records.
The Why can this user see this record? check in the sharing detail view (the Expand List option and the per-user Sharing Hierarchy button, available in Lightning on supported objects) answers a single user's question directly. Use it first when it is available, and fall back to queries when it is not.
Query the share table
The share table holds the grants that are stored as rows. For a custom object Invoice__Share, this query lists every row for one record.
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'Read the output in three parts:
UserOrGroupIdidentifies the grantee. An Id starting with005is a user. One starting with00Gis a group, role, or queue.AccessLevelis Read, Edit, or All. All appears for the owner's row.RowCausesays why the row exists. Owner, Manual, and RuleCause are common values. A sharing rule produces the causeRule.
Standard objects use a different name. The share object for Account is AccountShare, and for Opportunity it is OpportunityShare. Those objects use AccountAccessLevel and OpportunityAccessLevel and similar fields, with RowCause and the matching parent field such as AccountId.
Two limits matter when you read these results.
- Rows for role hierarchy access and implicit parent-child access are not all stored as visible share rows. An absent row does not prove the user has no access.
- A user can match through a group. If
UserOrGroupIdis a group Id, you must check the group's members, including nested groups and roles, to learn whether your user is in it.
Query the team tables
Account teams are stored separately from the share table. They also produce share rows, but the team table tells you the role the person was given.
SELECT Id, AccountId, UserId, TeamMemberRole, AccountAccessLevel
FROM AccountTeamMember
WHERE AccountId = '<account record Id>'If the user appears here, compare AccountAccessLevel with what they are trying to do. A team member with Read cannot edit, whatever the team role is called. Also check the related access levels for contacts, opportunities, and cases on the team, because those are set separately and can be lower than the account level.
Opportunity and case teams work the same way, with their own team member objects.
Diagnose a user who cannot see a record
Run through these causes, most common first.
- The user has no object Read permission. Check the profile and permission sets, and use the "View Summary" option on the permission set to confirm.
- The default is Private and nothing grants access. There is no share row, the user is not above the owner, and no rule matches.
- A sharing rule targets the wrong audience. The rule shares to a role, but the user is in a different role. Or it targets a public group the user was never added to.
- A criteria-based rule does not match. The field value differs from the criterion, for example
Status__cis "Overdue " with a trailing space or a different picklist value. - Recalculation is pending. After rule or role changes, access updates can lag. Check Setup, Background Jobs, for a running sharing job.
- A manual share was removed. Manual shares disappear when the owner changes, so a reassigned record can lose access for people who had it.
- The role hierarchy is not granting access. The box for hierarchies is cleared for that object, or the user sits in a sibling branch.
Diagnose a user who can see too much
The reverse case is harder, because several mechanisms stack and you must find all of them. Query the share table for the record, then compare each row's RowCause against your intent. A broad rule, a forgotten manual share, or a team membership each add access that nobody removes automatically. Remember that access is additive: you cannot take access away by adding another rule. You must remove the grant that provides it.
Also check View All and Modify All on the profile and permission sets. A user with Modify All Data sees everything, and no share row will reveal why.
Reproduce the user's view
When the cause is still unclear, confirm the symptom directly. Use Login As if your org allows it for the user, or run the query in Developer Console as a test user in Apex with System.runAs. Both show what the user truly sees, which is more reliable than reasoning from settings. Keep in mind that Login As needs the user's permission to grant it, and that anything you do is recorded under their name.
A worked example
A finance analyst reports she cannot open overdue invoices. The Invoice__c default is Private.
- She has Read on the object, so layer one passes.
- She is not the owner and is not above the owner in the hierarchy.
- The share query for one overdue invoice returns a row with
RowCauseset toRulefor a group Id. - That group is
Finance_Managers. She is not a member. She is an analyst, and the rule was written for managers.
The fix is to add her to the group, or to create a second rule for the analyst group. Adding her to the group works at once, though a large group can take time to recalculate.
Exercise
A sales manager can open an opportunity that a rep owns but cannot see the same rep's other private opportunities in a custom object that has Grant Access Using Hierarchies cleared. Name one check that explains this and one mechanism that could fix it.
Show answer
The role hierarchy only grants upward access when Grant Access Using Hierarchies is checked for the object, and here it is cleared, so the manager's access to the first opportunity must come from another source such as a share row, which you can confirm by querying the share table and reading RowCause. To fix it, either enable Grant Access Using Hierarchies for the custom object or create an owner-based sharing rule that shares the rep's records with the manager's role.
Exercise
A share query for a record returns no row for a user, yet the user can open the record. List two reasons this can be true.
Show answer
The user may own the record or have View All or Modify All permission, which do not need share rows. Hierarchy access and some implicit access are also not always stored as visible rows, so the user could be above the owner in the role hierarchy.