Sub topic 13
Share Objects, Access Levels, and Row Causes
This chapter assumes you know org-wide defaults, record ownership, the role hierarchy, and basic SOQL. It shows where Salesforce stores record access, so you can inspect it.
What a share object is
Each sharing mechanism ends up as rows in a share table. A share object is a hidden table that holds one row per grant of access to a record. Salesforce reads these rows to decide who can see a record beyond its owner.
Naming depends on the object:
- Standard objects use
<Object>Share, such asAccountShareorOpportunityShare. - Custom objects use
<Object>__Share, such asInvoice__Share.
A share table exists only when the org-wide default is not Public Read/Write. Under Public Read/Write, everyone already has full access, so no rows are needed.
Fields in a share row
| Field | Meaning |
|---|---|
| `ParentId` | The record being shared. Standard objects use a different name, such as `AccountId` on `AccountShare`. |
| `UserOrGroupId` | The user or group that receives access. |
| `AccessLevel` | `Read` or `Edit`. Some objects also allow `All`, which only the owner row uses. |
| `RowCause` | The reason the row exists. |
Row causes
The row cause records why access was granted. It also controls how the row is maintained.
| Row cause | Created by | Notes |
|---|---|---|
| Owner | Record ownership | Created and removed by Salesforce. Cannot be edited. |
| Manual | The Sharing button, or Apex | Removed when the owner changes. |
| Rule | Sharing rules | Maintained by recalculation. |
| Team | Account, opportunity, or case teams | Removed when the team member is removed. |
| Custom Apex reason | Apex sharing reason | Survives owner changes. Defined per custom object. |
The distinction between Manual and the other causes matters in practice. A Manual share disappears when the record owner changes. An Apex sharing reason is the way to keep a programmatic share through ownership changes.
Inspecting shares with SOQL
This query lists every share row for one invoice. Replace the placeholder with a real record Id.
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'Team members live in their own object. This query returns the account team for one account.
SELECT Id, AccountId, UserId, TeamMemberRole, AccountAccessLevel
FROM AccountTeamMember
WHERE AccountId = '<account record Id>'Team access also produces share rows with the Team cause, so you can see it in the share table too.
What the share table does not show
Share rows do not list everything. Access from the role hierarchy, from "View All" and "Modify All" permissions, and from "View All Data" and "Modify All Data" is calculated separately. A user can open a record with no share row at all. Keep this in mind when you read query results.
Common errors
- Querying
Invoice__Sharewhen the object is Public Read/Write. The object does not exist in that case. - Expecting a Manual share to survive an owner change.
- Treating the share table as the full answer to "who can see this?".
Exercise
A user was given access to an invoice through the Sharing button. Later the invoice owner changes. What happens to that user's share row, and which row cause applied to it?
Show answer
The row had the Manual row cause. Salesforce removes Manual shares when the record owner changes, so the user loses that access unless another mechanism, such as a sharing rule or an Apex sharing reason, grants it.