Sub topic 7
Owner-based sharing rules
Owner-based sharing rules give access to records based on who owns them. This chapter assumes you know org-wide defaults (OWD), the role hierarchy, and public groups and queues, which earlier chapters covered. It also assumes you know that sharing can only open access beyond the OWD, never restrict it.
What an owner-based rule does
An owner-based sharing rule says: "Records owned by members of source X are shared with target Y at access level Z." It is the right tool when a whole team's records should be visible to another team, no matter what the records contain.
Every rule has the same parts:
| Part | What you choose | Notes |
|---|---|---|
| Object | The object the rule applies to | Each object has its own rules list. |
| Rule type | Based on record owner | The alternative is criteria-based, covered in the next chapter. |
| Owned by members of | Public group, role, or role and subordinates | This is the source set of owners. |
| Share with | Public group, role, or role and subordinates | This is the target set of users. |
| Access level | Read Only or Read/Write | Which levels are offered depends on the object and the OWD. |
Some objects also let you set access for related records. For example, an account sharing rule can set the access level for contacts, opportunities, and cases on the shared accounts.
Why the source and target matter
The source decides which records are shared. The target decides who gets the access. Both can be one of three kinds of member set:
- Public group. A flexible list of users, roles, and other groups. Use it when the set doesn't match one branch of the hierarchy.
- Roles. Every user in one role.
- Roles and subordinates. Every user in the role plus everyone below it. This option can be missing if Experience Cloud site roles are involved, and on some orgs you may see "Roles, Internal Subordinates" instead.
Pick the smallest set that meets the requirement. Wide targets such as "Roles and subordinates" on a top-level role add many share rows and slow recalculation.
A worked example
Suppose the Invoice object has an OWD of Private. Invoices are owned by the Sales team in the role Sales_West. The finance analysts in the public group Finance_Analysts need to read all of them.
- In Setup, search for Sharing Settings.
- Find the Invoice Sharing Rules list and click New.
- Enter the label
Share West Invoicesand let the API name fill in. - For Rule Type, select Based on record owner.
- For Owned by members of, select Roles and Subordinates and choose
Sales_West. - For Share with, select Public Groups and choose
Finance_Analysts. - Set Access Level to Read Only and save.
Salesforce then recalculates sharing for the object. When the job finishes, each Finance analyst can open any invoice owned by a user in Sales_West or below. Invoices owned by users elsewhere stay hidden from them.
The same rule can be deployed as metadata. The Metadata API calls owner-based rules sharingOwnerRules. This is the XML form of the example above.
<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
<sharingOwnerRules>
<fullName>Share_West_Invoices</fullName>
<accessLevel>Read</accessLevel>
<label>Share West Invoices</label>
<sharedFrom>
<roleAndSubordinates>Sales_West</roleAndSubordinates>
</sharedFrom>
<sharedTo>
<group>Finance_Analysts</group>
</sharedTo>
</sharingOwnerRules>
</SharingRules>Compare this with the criteria-based version in the next chapter. There, a criteriaItems block replaces sharedFrom.
How the rule shows up in data
Each rule produces rows in the object's share table. For a custom object such as Invoice, that table is Invoice__Share. For rule-based shares, the RowCause is Rule. For standard objects the share tables are named differently, such as AccountShare and OpportunityShare, but the idea is the same.
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'For an invoice owned by a Sales_West user, you would expect a row with RowCause = 'Rule' and a UserOrGroupId pointing to the Finance_Analysts group. Note that the share goes to the group, not to each analyst. Group membership is resolved by Salesforce separately, so adding an analyst to the group later grants access without creating more rows on the invoice.
Rules for how rules behave
These behaviors explain most surprises.
- Rules only add access. They cannot reduce what OWD, ownership, or the role hierarchy already provide. If an OWD is Public Read/Write, a Read Only rule changes nothing.
- Access levels cannot go below the OWD. The list of choices is limited to levels above the OWD, so a Public Read Only object only offers Read/Write.
- Rules are additive. If two rules both reach a user, the user gets the higher level.
- Rules need a restrictive OWD. If the OWD is Public Read/Write, there is nothing to open up.
- Grants flow upward too. Users above the target in the hierarchy gain access to the shared records, if "Grant Access Using Hierarchies" is enabled for the object.
- Ownership by queues counts only in some cases. Records owned by a queue can be matched when the queue is in a public group used as the source. Check this for your object before relying on it.
- Sharing is not field security. A rule opens records, but field-level security and object permissions still apply. A user with Read access to a record but no Read permission on the object still sees nothing.
Recalculation and timing
Creating, editing, or deleting a rule starts a recalculation in the background. For large data volumes, the job can take minutes to hours, and access may be incomplete while it runs. You can see the status in the Sharing Settings page under Setup, and you can run a manual recalculation from the same list. Deferred sharing calculations can pause the job during bulk loads.
Changing a record owner triggers recalculation for that record only, which is why ownership changes take effect right away in normal use.
Common mistakes
- Using the wrong source. A rule keyed to the wrong role shares nothing, and there is no error message. Test with a record you know matches.
- Forgetting the OWD. An engineer adds a rule on an object that is already Public Read Only and asks for Read Only. Nothing changes.
- Sharing with a role when a group is needed. Roles can't express "these three roles plus two users." Use a public group.
- Overlapping rules. Many near-duplicate rules make troubleshooting harder. Merge them when the source and target sets are the same.
- Expecting access to the owner's other records. The rule applies only to the object it is defined on, plus the related records you explicitly chose on supported objects.
- Ignoring the limits. Each object can have a limited number of owner-based and criteria-based rules, and the limit depends on the edition. Check current limits before designing a design with dozens of rules.
Choosing owner-based rules
Choose an owner-based rule when the people who own the data, rather than the data's content, determine who should see it. If the requirement mentions a field value, such as a status or region, use a criteria-based rule. If only one record needs sharing, use manual sharing.
Exercise
An Invoice object has an OWD of Public Read Only. You create an owner-based rule that shares invoices owned by SalesWest with FinanceAnalysts at Read Only. Finance reports no change in access. Why, and what would make the rule useful?
Show answer
Public Read Only already gives every user read access, and a rule cannot grant a level at or below the OWD, so the rule adds nothing. The rule becomes useful only if the OWD is changed to Private, or if the rule grants Read/Write, which is above the OWD.
Exercise
A record owned by a user in the source role is transferred to a user in a different role outside the rule's source set. What happens to the share row with RowCause Rule on that record, and how could you confirm it?
Show answer
The rule no longer matches the new owner, so Salesforce removes the rule-based share row when it recalculates that record. You can confirm by querying Invoice__Share for the record's ParentId and checking that no row with RowCause = 'Rule' remains for the target group.