Sub topic 6
What sharing rules do and what they cannot do
Prerequisites and scope
This chapter assumes you know what a record owner is, how org-wide defaults (OWD) set the baseline, and how the role hierarchy opens access upward. It also assumes you know that profiles and permission sets control object and field access. Public groups and queues appear here as sharing targets. Owner-based and criteria-based rules each get their own chapter, so this one covers the shared model and the limits.
What a sharing rule is
A sharing rule is an automatic exception to your org-wide defaults. It gives extra users read-only or read/write access to records they would not otherwise see. You define the rule once. Salesforce then evaluates it for every matching record, including records created later.
A rule has three parts:
- Which records to share. Either records owned by certain users (owner-based) or records whose field values match criteria (criteria-based).
- Who receives access. A public group, a role, a role and its subordinates, or (for some rule types) a queue or territory.
- What access level they get. Read Only or Read/Write. Some objects, such as accounts, also let you set access to related contacts, opportunities, and cases.
Salesforce implements the result as rows in the object's share table. The share table is the database table that stores record-level grants. Share tables get their own chapter. For now, remember that a rule does not change the record. It adds share rows for it.
Where sharing rules fit in the access model
Sharing rules only add access. The order of reasoning is:
- Object permissions on the profile or permission sets decide whether the user can work with the object at all.
- OWD sets the baseline for records the user does not own.
- The role hierarchy, rules, teams, and manual shares open access beyond that baseline.
What sharing rules can do
- Open access to a defined set of records for a defined set of users. Example: all invoices owned by the Sales West role are readable by the Finance Managers group.
- Grant Read Only or Read/Write. The rule can raise access above the OWD. It never lowers it.
- Work without involving the record owner. Owners do not need to act. The rule applies to existing and new records.
- Target groups, roles, and roles with subordinates. One rule covers many users, and membership changes take effect without editing the rule.
- Stack with other mechanisms. If a user qualifies through a rule and a team, Salesforce grants the highest access level among them.
- Be deployed as metadata. The Metadata API represents them as
SharingRules, which lets you move them between sandboxes and production.
Here is a criteria-based rule in Metadata API form. It gives the FinanceManagers public group read access to invoices whose `Status_c equals Overdue`.
<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
<sharingCriteriaRules>
<fullName>Share_Overdue_Invoices</fullName>
<accessLevel>Read</accessLevel>
<label>Share Overdue Invoices</label>
<sharedTo>
<group>Finance_Managers</group>
</sharedTo>
<criteriaItems>
<field>Status__c</field>
<operation>equals</operation>
<value>Overdue</value>
</criteriaItems>
</sharingCriteriaRules>
</SharingRules>Salesforce evaluates the criteria when a record is created or edited. If Status__c changes to Overdue, the share row appears. If it changes away from Overdue, the row is removed.
What sharing rules cannot do
They cannot restrict access
A rule never takes access away. If the OWD is Public Read/Write, a rule has nothing to add. To make records more private, change the OWD to something more restrictive and then open access back up where needed.
They cannot work when the OWD is already open enough
Sharing rules are available only for objects whose OWD is Private or Public Read Only. For a Public Read/Write object, users already have the maximum access and the rule would add nothing. Setup does not let you create one.
They cannot override object or field permissions
A rule shares the record, not the fields or the object. A user who sees a record through a rule still cannot see fields hidden by field-level security, and still cannot edit if the profile lacks Edit permission. The effective access is the lower of the record access and the object permission.
They cannot share with an individual user directly
Rule targets are groups, roles, and roles with subordinates. To share with one named person, put that person in a public group, or use manual sharing or a team. Creating a one-person group per rule is a sign that you want a different mechanism.
They cannot target a single record
Rules apply to every record that matches. They are the wrong tool for "share this one invoice with Priya for a week." That is manual sharing. Manual shares are also the tool when the owner decides case by case.
They cannot match on anything you like
Criteria-based rules compare field values on the record itself. They cannot test the user, the time of day, or fields on related records. Some field types are unsupported in criteria, such as formula fields whose value depends on another object, depending on the object and edition. Check the limits that apply to your org before you design around a field.
They cannot grant more than the rule allows on related records
For accounts, the rule can include access to contacts, opportunities, and cases, but each is capped by what you set. Controlled-by-parent objects have no rule of their own. They follow the parent's sharing.
Common errors
| Symptom | Likely cause | What to check |
|---|---|---|
| The new rule option is missing for an object | OWD is Public Read/Write, or the object is controlled by its parent | Setup, Sharing Settings, OWD for the object |
| A user is in the target group but sees nothing | The user lacks object Read permission, or the rule is still recalculating | Profile and permission sets, then the rule's status |
| User sees the record but cannot edit it | Rule gives Read Only, or the profile lacks Edit | Rule access level and object permissions |
| A record stopped being shared | A field value no longer matches the criteria, or the owner changed to someone outside the rule | The record's current field values and owner |
| A rule appears to give too much | Another mechanism, such as the role hierarchy or a team, grants the extra access | Share rows and their row causes |
Checking the result
The quickest way to confirm what a rule did is to query the share table. For a custom object such as Invoice__c, the share table is Invoice__Share. This query lists every grant on one record.
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'The RowCause column says why each row exists. Rows created by a sharing rule have a rule-related cause, which differs from Owner and Manual. If you expected a row for your rule and it is missing, either the record did not match, or the target group did not contain the user.
Design guidance
- Prefer a rule over repeated manual shares when the pattern repeats. Manual shares do not scale, and they are removed if the owner changes.
- Target public groups rather than individual roles when membership changes often. You then edit the group instead of the rule.
- Keep rule counts modest. Every rule adds work to recalculation, and orgs have per-object limits on rules.
- Name rules after the business reason, such as
Share_Overdue_Invoices, so a later administrator knows why the access exists.
Exercise
The Case object has OWD Private. A support manager reports that a rule shares all Priority = High cases with the Escalations group as Read Only, yet an Escalations member cannot open a high-priority case that they were sent a link to. Name two things you would check, and say whether adding a second rule granting Read/Write would fix a "cannot edit" complaint.
Show answer
First, check the member's profile and permission sets for Read permission on Case, since a rule cannot grant object access. Second, confirm the member is actually in the Escalations group and that the case's Priority is High, then query CaseShare for that case to see whether a rule-caused row exists for the group. A second rule granting Read/Write would fix a "cannot edit" complaint only if the user's profile or permission set also grants Edit on Case, because the effective access is limited by object permissions. The higher of the two record-level grants would apply.
Exercise
Why can you not create a sharing rule on an object whose OWD is Public Read/Write, and what do you do if you need that object to be more restricted?
Show answer
Users already have full access to every record, so a rule has nothing to add. To restrict the object, change the OWD to Private or Public Read Only, then use rules, teams, or manual shares to open access where it is needed.