SharingRules is the per-object container for rules that grant record access to selected users or groups. It contains criteria-based, ownership-based, territory-based, and guest-user rules in sharingCriteriaRules, sharingOwnerRules, sharingTerritoryRules, and sharingGuestRules. These are sharing definitions, not the runtime share records created when Salesforce calculates access.
The container is named for its object, such as Account or ObjA__c. Each contained rule has its own fullName, distinct from the object-named container. Keep these identities separate when selecting components for retrieval, deployment, or deletion.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
Identifies the component at its own level: the object name for the SharingRules container, or the individual rule name inside a rule collection. |
sharingCriteriaRules |
Contains SharingCriteriaRule definitions, which select records through field criteria. |
sharingGuestRules |
Contains SharingGuestRule definitions for guest-user access. These rules grant only Read access. |
sharingOwnerRules |
Contains SharingOwnerRule definitions, which select records by their owners. |
sharingTerritoryRules |
Contains SharingTerritoryRule definitions. These inherit the ownership-based structure, including sharedFrom and sharedTo. |
accessLevel |
Required on each rule. Specifies the record access granted. For guest-user rules, the only permitted value is Read. |
sharedTo |
Required on each rule. Identifies the recipients of access through the SharedTo supporting structure. |
sharedFrom |
Required for ownership-based rules and inherited by territory-based rules. Identifies the record-owner population, not the recipients. |
criteriaItems |
Defines the conditions for criteria-based and guest-user rules. Each condition identifies a field, an operation, and a comparison value. |
booleanFilter |
Specifies advanced Boolean logic combining the conditions in criteriaItems. |
includeRecordsOwnedByAll |
Required for criteria-based rules. Includes or excludes records owned by users who cannot have an assigned role. Cannot be edited after creation. |
includeHVUOwnedRecords |
Required for guest-user rules. Controls inclusion of records owned by high-volume community or site users. Defaults to false and cannot be edited after creation. |
accountSettings |
Controls access to records associated with an account. Its required caseAccessLevel, contactAccessLevel, and opportunityAccessLevel each accept None, Read, or Edit. Excluded from guest-user rules. |
label |
Required display label for an individual rule. It is separate from the rule's fullName. |
description |
Describes an individual rule. Maximum length is 1000 characters. |
Behavior and Constraints
Access permissions
Accessing this metadata requires View Setup and Configuration. Editing it requires Manage Sharing.
Record selection and owner inclusion
Criteria-based and guest-user rules select records using criteriaItems and booleanFilter. The exposed filter operations are contains, equals, excludes, greaterOrEqual, greaterThan, includes, lessOrEqual, lessThan, notContain, notEqual, startsWith, and within.
For criteria-based rules, includeRecordsOwnedByAll determines whether qualifying records include those owned by users who cannot have an assigned role. These owners include high-volume users and system users such as automated process users.
Guest-user rules use a different flag: includeHVUOwnedRecords. The documented default owner population includes authenticated users, guest users, and queues. Including records owned by high-volume community or site users requires this flag to be true; its default is false.
Both owner-inclusion flags are creation-time decisions. Neither can be changed after the rule is created, so an update deployment cannot treat either field as an ordinary switch.
Ownership-based rules instead require sharedFrom to describe whose records are selected. Their sharedTo describes who receives access. Territory-based rules inherit this same source-and-recipient structure.
Account and guest-user grants
For account sharing, accessLevel controls access to the account itself. accountSettings separately controls access to its associated cases, contacts, and opportunities. Assess both the account grant and these related-record grants; the account's accessLevel alone does not describe the complete rule.
SharingGuestRule permits only Read access and excludes accountSettings. A shared element schema can display accountSettings beneath sharingGuestRules, but that does not make it a supported guest-rule setting.
Recipient and owner selectors
SharedTo is the supporting structure used by sharedTo and by the sharedFrom element on ownership-based and territory-based rules. Its selectors describe different populations:
-
Groups:
group,allCustomerPortalUsers,allInternalUsers, andallPartnerUsersidentify group populations.channelProgramGroupandchannelProgramGroupsidentify system-managed groups containing partner members of the corresponding channel programs or levels. -
Roles:
roleselects roles directly.roleAndSubordinatesandroleAndSubordinatesInternalbroaden the population through the role hierarchy.portalRoleselects users in a portal role; the portal-role descendant selector also includes users below that role. -
Queues:
queueapplies only to Lead, Case, and custom-object sharing rules. -
Territories:
territoryselects territories, whileterritoryAndSubordinatesalso includes descendants in the territory hierarchy. -
Guest users:
guestUseris permitted only withSharingGuestRule. Its values are guest user nicknames, not site developer names or record IDs.
Do not assume roleAndSubordinates and roleAndSubordinatesInternal are interchangeable. roleAndSubordinates can include portal accounts below the selected roles. It is available only when digital experiences is enabled and Experience Cloud site users have external account roles other than a shared person account role.
For Sales Territories, both sharedFrom and sharedTo serialize territory and territoryAndSubordinates values as modelName.territoryName. Use the active territory model's API name and the territory's API name.
A rule's text does not fully describe its current access impact. Changes to referenced fields or criteria values can change which records qualify. Changes to group membership, roles, or territory hierarchies can change the selected population without changing the rule definition. Actual access therefore depends on record values, ownership, membership, and hierarchy state.
Deployment and Retrieval
SharingRules supports retrieval, deployment, and deletion of sharing-rule metadata. The interface supports operations across the organization's sharing rules, and package.xml, the component-selection manifest, supports the * wildcard. Manual sharing is outside this metadata interface.
In Metadata API format, components reside in the sharingRules directory and use the .sharingRules suffix, such as Account.sharingRules or ObjA__c.sharingRules. The rule families are contained within the object-named component.
The naming pattern is <objectName>. Use the entire file base, including any namespace, to identify the associated object. This association can concern a standard or custom object; an object-named container does not necessarily refer to a newly created custom object.
Keep container identity separate from child-rule selection. The Metadata API documentation supplies manifest examples selecting SharingCriteriaRule and SharingOwnerRule with members such as ObjA__c.*, but also states that operations by rule type are unavailable. This inconsistency is described below. Those examples do not rename the containing SharingRules component.
SharingBaseRule supplies common rule fields but cannot be created directly. Use the concrete rule structures contained under SharingRules.
Deployment diagnosis must also account for immutable owner-inclusion flags and sharing-calculation activity. Changing either inclusion flag on an existing rule conflicts with its creation-only constraint. A combined sharing-model and rule deployment has also been reported to encounter calculation contention; the reported sequencing workaround is described under Reported Issues.
Relationships
Rules connect field criteria to recipient or owner populations through their nested elements. These connections describe possible references, not proof that every related component is used by a particular rule.
Name-based association: CustomObject is associated through the complete SharingRules component name, using the pattern <objectName>. This is not an XML element reference and does not, by itself, require the components to be deployed together or in a particular order.
References
-
CustomField:fieldwithincriteriaItems. -
CustomSite:guestUser, using guest user nicknames in the site's metadata context. -
Group:allCustomerPortalUsers,allInternalUsers,allPartnerUsers,channelProgramGroup,channelProgramGroups,group. -
Queue:queue. -
Role:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
TerritoryModel:territory,territoryAndSubordinates.
Documentation Inconsistencies
-
Rule-type selection: The SharingRules documentation states that sharing rules cannot be retrieved, deleted, or deployed by rule type. The same page provides manifest examples selecting
SharingCriteriaRuleandSharingOwnerRulewith members such asObjA__c.*. This leaves the child-selection guidance inconsistent, while the object-named container identity remains unchanged. -
Portal-role selector capitalization: Salesforce's
SharedTodocumentation usesportalRoleandSubordinates, while the exposed element schema usesportalRoleAndSubordinates. These differ in capitalization and should not be silently treated as interchangeable.
Reported Issues
- A combined sharing-model and rule deployment can encounter calculation contention. In December 2023, a deployment changing an object's sharing model from public to private while adding 36 rules reportedly failed with "sharing operation already in progress". The reporter resolved that case by deploying the sharing-model change first and the rules afterward. This is a sequencing workaround for that condition, not a general limit on the number of rules in one deployment. Reported deployment sequence.
- Deferring sharing calculations was proposed as another way to avoid contention. In a 2016 response to a multiple-rule deployment failure, a community answer suggested asking Salesforce Support to enable Defer Sharing Calculations so calculations could be suspended during rule deployment and run afterward. Treat this as a reported option, not a requirement for every sharing-rule deployment. Calculation-deferral suggestion.
-
Deleting a standard object container can fail even though sharing-rule deletion is supported. An org-cleanup answer updated in 2022 excluded
SharingRulesfrom bulk destructive changes after reporting "The SharingRules called 'Account' is standard and cannot be deleted". That report concerns deletion of theAccountcontainer, not proof that its individual rule definitions cannot be removed. Standard-container deletion report. -
A runtime share-row ID may not provide a lookup to the originating rule. In 2020, a community response reported no direct lookup from
AccountShareto the sharing rule itself. This reinforces the distinction between runtime share records and rule metadata; the response did not establish a supported ID-to-fullNamemapping. Share-row mapping discussion. -
A successful deployment was reported to omit custom-object criteria rules. In November 2023, a manifest-based scratch-org deployment reportedly deployed Account rules but omitted custom-object rules. The manifest combined object-qualified
SharingCriteriaRulemembers with a wildcardSharingRulesselection. No answer or confirmed cause was supplied, so the report does not establish a general restriction on deploying custom-object sharing rules. Missing custom-object rules report.
Common Questions
Where are SharingRules files stored, and what are they named?
In Metadata API format, they are stored in sharingRules with the suffix .sharingRules. The file base is the entire object API name, including any namespace. Individual rule names appear as fullName values inside that container.
Can I retrieve only owner-based or criteria-based sharing rules?
The official guidance is inconsistent. It says operations by rule type are unavailable, but also shows SharingOwnerRule and SharingCriteriaRule manifest selections using members such as ObjA__c.*. These selections concern child rules, not the identity of the object-named SharingRules container.
Can I change includeRecordsOwnedByAll or includeHVUOwnedRecords after creating a rule?
No. includeRecordsOwnedByAll on criteria-based rules and includeHVUOwnedRecords on guest-user rules cannot be edited after creation. A deployment must account for that immutability rather than treating them as updateable switches.
Can guest-user sharing rules grant Edit access or include accountSettings?
No. SharingGuestRule permits only Read access and excludes accountSettings. Its sharedTo.guestUser values are guest user nicknames, not site developer names or record IDs.
Why does deploying sharing rules return "sharing operation already in progress"?
A December 2023 report encountered that error when changing an object's sharing model from public to private and adding 36 rules together. Deploying the model change first and the rules afterward resolved that case. It does not establish a general rule-count limit.