Sub topic 11
When the hierarchy is not enough: sharing rules, teams and manual sharing
This chapter assumes you know org-wide defaults (OWD), record ownership, and how the role hierarchy gives managers access to records owned by users below them. It also assumes basic SOQL.
The gap the hierarchy leaves
The role hierarchy only opens access upward. A sales rep in one branch cannot see a peer's private accounts. A support team in a different branch cannot see accounts owned by sales. When OWD is Private or Public Read Only, you need a way to widen access sideways or across branches without loosening the baseline for everyone.
Salesforce gives you three tools. Each one adds access and none of them can remove it.
| Tool | Who sets it up | Scope | Best for |
|---|---|---|---|
| Sharing rule | Admin, in Setup | Many records, matched by owner or criteria | Predictable, ongoing needs |
| Team (account, opportunity, case) | Record owner or team members | One record | Collaboration on a specific deal or customer |
| Manual share | Record owner, or a user with Full Access | One record | One-off exceptions |
Sharing rules
A sharing rule grants access to a set of records to a public group, role, or role and subordinates. There are two types:
- Owner-based rules share records owned by members of one group with another group. For example, share all accounts owned by the West Sales role with the Support role.
- Criteria-based rules share records whose field values match a condition. For example, share every opportunity where Stage is Closed Won with the Finance group.
A rule can grant Read Only or Read/Write. It can only be more permissive than OWD. A rule granting Read Only on an object whose OWD is Public Read/Write has no effect.
The rule creates rows in the object's share table, with a RowCause of Rule. Changes to rules trigger a sharing recalculation, which can take a while on large data volumes.
Teams
Account teams, opportunity teams and case teams let the people working a record gain access to it. Each team member gets a role on the team, and each role maps to an access level on the record. Team access is stored as share rows with RowCause Team.
Manual sharing
When a user clicks the Sharing button on a record, they create a manual share. It is stored with RowCause Manual. The record owner, a user above the owner in the hierarchy, and an administrator can use it. Manual shares are lost when the record's owner changes, so do not rely on them for lasting access.
Account acc = [SELECT Id FROM Account LIMIT 1];
AccountShare share = new AccountShare();
share.AccountId = acc.Id;
share.UserOrGroupId = UserInfo.getUserId();
share.AccountAccessLevel = 'Read';
share.OpportunityAccessLevel = 'None';
share.RowCause = Schema.AccountShare.RowCause.Manual;
insert share;Choosing between them
To see which mechanism gave a user access, query the share table and read the RowCause:
SELECT Id, AccountId, UserOrGroupId, AccountAccessLevel, RowCause
FROM AccountShare
WHERE AccountId = '001XXXXXXXXXXXXXXX'Common errors
- Expecting a rule to restrict access. Rules only open it.
- Creating a rule for a Public Read/Write object and wondering why nothing changes.
- Using manual shares for permanent access, then losing it when ownership changes.
- Forgetting that large rule changes need recalculation time before users see results.
Exercise
An account has OWD Private. A support user in a different branch needs ongoing Read access to every account owned by the West Sales role. Which tool do you use, and which RowCause appears in AccountShare?
Show answer
Use an owner-based sharing rule that shares accounts owned by the West Sales role with the support user's group or role, at Read Only. The share rows have RowCause Rule.