SharingCriteriaRule grants record access to selected recipients when records satisfy field-based criteria. Each rule sits in an object's SharingRules container under sharingCriteriaRules and inherits common access and recipient settings from SharingBaseRule.
The rule's effect depends on four settings working together: which records match, which owners are eligible, who receives access, and what access they receive. Do not confuse the individual rule with its object-level container, or with SharingGuestRule, which uses a different recipient model.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
Identifies the individual criteria rule within the object's sharing-rules container. The container supplies the object context. |
label |
Required display label for the rule. |
accessLevel |
Required access level granted to the selected recipients for matching records. |
sharedTo |
Required recipient selection. Its SharedTo structure can identify groups, roles, queues, or territories, subject to selector-specific restrictions. |
includeRecordsOwnedByAll |
Required Boolean. Includes otherwise-matching records owned by users who cannot have an assigned role when true, and excludes them when false. Cannot be edited after creation. |
criteriaItems |
Individual filter conditions that select records. Interpret these together with booleanFilter. |
field |
Within a criteria item, identifies the evaluated field. It can reference CustomField metadata. |
operation |
Within a criteria item, specifies the comparison. Exposed values are contains, equals, excludes, greaterOrEqual, greaterThan, includes, lessOrEqual, lessThan, notContain, notEqual, startsWith, and within. |
value |
Within a criteria item, supplies the value used by the comparison. |
booleanFilter |
Advanced filter logic that combines the criteria items. |
accountSettings |
For Account rules, controls access to associated cases, contacts, and opportunities separately from access to the Account itself. |
caseAccessLevel |
Required within accountSettings. Grants None, Read, or Edit access to associated cases. |
contactAccessLevel |
Required within accountSettings. Grants None, Read, or Edit access to associated contacts. |
opportunityAccessLevel |
Required within accountSettings. Grants None, Read, or Edit access to associated opportunities. |
Behavior and Constraints
Owner eligibility is not the same as whether an owner currently has a role. includeRecordsOwnedByAll concerns users who cannot have an assigned role, such as high-volume users and system users, including automated process users. Setting it to true includes their records only if those records also satisfy the rule's criteria. Setting it to false excludes those records.
Changing criteriaItems or booleanFilter can change which records are shared without changing sharedTo or accessLevel. The conditions form one selection expression; they are not an unordered list of independent access grants.
sharedTo identifies recipient scopes, not a fixed list of every user who currently receives access. Determining the actual recipients requires the selected groups, roles, territories, and their current membership or hierarchy.
-
groupselects groups.allCustomerPortalUsers,allInternalUsers, andallPartnerUsersidentify groups for those user populations.allInternalUserscovers internal and nonportal users. -
channelProgramGroupandchannelProgramGroupsidentify system-managed groups containing partner members of the corresponding channel programs or levels. -
roleselects listed roles.roleAndSubordinatesandroleAndSubordinatesInternalextend access down the role hierarchy. -
roleAndSubordinatescan also include portal accounts below the selected roles when portal accounts are enabled. This selector is available only when digital experiences is enabled and Experience Cloud site users are created with external account roles other than a shared person account role. -
portalRoleselects users in a portal role. The portal-role subordinate selector also includes users below that role; its spelling discrepancy is described below. -
queueapplies only to Lead, Case, and custom-object sharing rules. -
territoryselects territories, whileterritoryAndSubordinatesalso includes subordinate territories. For Sales Territories, both usemodelName.territoryName: the active territory model's API name followed by the territory's API name.
Although the shared SharedTo structure exposes guestUser, that selector is reserved for SharingGuestRule. It is not valid for SharingCriteriaRule.
For Account rules, review accountSettings as well as accessLevel. A rule can affect access to related cases, contacts, and opportunities, not just the Account record. All three child-access settings are required within that structure.
Accessing sharing-rule configuration requires View Setup and Configuration; editing it requires Manage Sharing. These administrative permissions are separate from the record access granted by the rule.
Deployment and Retrieval
The object-level component is stored in the sharingRules directory with the object's API name and the .sharingRules suffix, such as Account.sharingRules or ObjA__c.sharingRules. Its SharingRules container can contain criteria-based, owner-based, territory-based, and guest-user rules. A criteria rule remains an individual entry under sharingCriteriaRules, with its own fullName.
Salesforce's SharingRules documentation includes a package.xml example with type name SharingCriteriaRule and member ObjA__c.*, selecting criteria rules for that custom object. The page also documents wildcard support. Keep this type-specific selection separate from selecting the containing SharingRules component; the documentation contains a conflicting statement about rule-type operations, described below.
A difference in includeRecordsOwnedByAll is not an ordinary in-place update: Salesforce does not allow that field to be edited after the rule is created.
SharingBaseRule supplies inherited settings but cannot be created directly. Deploy the concrete rule through the sharing-rule component structure rather than treating the base definition as a deployable rule.
Community reports describe migration through change sets and object-qualified manifest members. They also include a case where a successful deployment omitted custom-object criteria rules. Those reports and their conditions are listed under Reported Issues.
Relationships
SharingCriteriaRule inherits common settings from SharingBaseRule and uses the SharedTo helper structure for recipients. Its field references and recipient selectors connect it to the types below. These connections describe possible references, not a list of actual recipients or a mandatory deployment order.
References
-
CustomField:fieldwithincriteriaItems. -
Group:group,allCustomerPortalUsers,allInternalUsers,allPartnerUsers,channelProgramGroup,channelProgramGroupswithinsharedTo. -
Role:role,roleAndSubordinates,roleAndSubordinatesInternal,portalRole,portalRoleandSubordinateswithinsharedTo. The last selector has a casing discrepancy described below. -
Queue:queuewithinsharedTo. -
TerritoryModel:territory,territoryAndSubordinateswithinsharedTo.
Referenced By
-
SharingRules:sharingCriteriaRules, which contains the object's criteria-based rules.
Documentation Inconsistencies
-
Rule-type selection conflicts with the overview restriction. The SharingRules overview says sharing rules cannot be retrieved, deleted, or deployed by rule type. The same page provides a manifest example selecting
ObjA__c.*underSharingCriteriaRule. The broad restriction conflicts with the type-specific example; it does not erase the distinction between an individual criteria rule and its object-level container. -
The portal-role subordinate selector has two spellings. The exposed element name is
portalRoleAndSubordinates, while Salesforce'sSharedTodocumentation names itportalRoleandSubordinates. This is a serialization-name discrepancy, meaning a difference in the element name written to metadata, not a documented difference in recipient behavior.
Reported Issues
-
A successful deployment may still leave custom-object criteria rules missing, according to one report. In 2023, a user deploying to a scratch org with
sf project deploy startreported that Account sharing rules appeared but custom-object rules did not. The manifest selected custom objects, object-qualifiedSharingCriteriaRulemembers, and wildcardSharingRules. The discussion has no answer establishing a cause or workaround. Scratch-org deployment report. -
A deployment rejection prompted a recommendation to check both the manifest member and its type. In a 2016 discussion reporting "Component type not permissible in destination Organization," an answer recommended the member form
ObjectAPIName.SharingRuleNameunder the correct rule type, withLead.testShareRuleunderSharingCriteriaRuleas an example. The answer was not accepted, so it is a diagnostic suggestion rather than a confirmed resolution. Manifest naming discussion. -
Change sets were reported as an alternative to manually recreating rules. A 2017 accepted answer stated that criteria-based and owner-based sharing rules for standard and custom objects could be moved through change sets. It also showed
ObjA__c.*underSharingCriteriaRulefor manifest-based migration. Sharing-rule migration discussion.
Common Questions
Can I change includeRecordsOwnedByAll on an existing sharing rule?
No. The field is required and cannot be edited after creation. It controls records owned by users who cannot have an assigned role, not simply users who currently have no role.
How do I retrieve criteria-based sharing rules for one object?
Salesforce's manifest example uses SharingCriteriaRule with an object-qualified member such as ObjA__c.*. The rules are contained in that object's .sharingRules file. The same documentation also contains a conflicting broad restriction on rule-type retrieval, so distinguish the type-specific selection from the object-level container.
Does sharedTo list every user who receives access?
No. It identifies recipient scopes such as groups, roles, queues, and territories. The actual users depend on current membership and hierarchy, including any subordinate scope selected by the rule.
Can an Account criteria rule share related cases, contacts, and opportunities?
Yes. accountSettings separately controls those records through caseAccessLevel, contactAccessLevel, and opportunityAccessLevel. Each accepts None, Read, or Edit.
Can I use guestUser in a SharingCriteriaRule?
No. Although guestUser appears in the shared recipient structure, it is valid only for SharingGuestRule.