SharingTerritoryRule defines a territory-based rule that grants record access to a specified population of users. It is stored in the sharingTerritoryRules collection of an object's SharingRules component. The rule identifies the source record owners, the recipients, and the access to grant.
This is not a criteria-filter rule. It inherits sharedFrom from SharingOwnerRule and the access-grant settings from SharingBaseRule. A territory-based rule does not have to share with another territory: its recipients can, for example, be users in a role.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The contained rule's metadata name. This is separate from the parent SharingRules component's object name. |
label |
Required. The rule's display label. |
accessLevel |
Required. The access granted to the primary records. For account rules, this does not describe access to associated cases, contacts, or opportunities. |
sharedFrom |
Required. Identifies the source record-owner population using the SharedTo selector structure. |
sharedTo |
Required. Identifies the users who receive access, also using the SharedTo selector structure. |
accountSettings |
Controls access to cases, contacts, and opportunities associated with the shared accounts. |
caseAccessLevel |
Required within accountSettings. Associated-case access: None, Read, or Edit. |
contactAccessLevel |
Required within accountSettings. Associated-contact access: None, Read, or Edit. |
opportunityAccessLevel |
Required within accountSettings. Associated-opportunity access: None, Read, or Edit. |
territory |
Selects named territories within sharedFrom or sharedTo. For Sales Territories, values use modelName.territoryName. |
territoryAndSubordinates |
Selects named territories and territories below them in the hierarchy. For Sales Territories, values use modelName.territoryName. |
role |
Selects named roles within a source or recipient population. |
roleAndSubordinates |
Includes subordinate roles and can include portal accounts below the selected roles. Its availability depends on Digital Experiences and external-role configuration. |
roleAndSubordinatesInternal |
Selects roles and subordinate roles for the internal audience. Do not substitute it for roleAndSubordinates without considering the audience difference. |
description |
Describes the rule, with a maximum of 1000 characters. |
Behavior and Constraints
Read source, recipients, and access together
sharedFrom identifies whose owned records are shared. sharedTo identifies who receives access. accessLevel specifies the access granted to those primary records. Neither selector alone describes the complete rule.
For account sharing, inspect accountSettings separately. Its three required access-level fields control associated cases, contacts, and opportunities independently of the primary account access setting.
Territory names include the active model
For Sales Territories, both territory and territoryAndSubordinates use modelName.territoryName in both sharedFrom and sharedTo. Here, modelName is the active territory model's API name, and territoryName is the territory's API name. These are model-qualified names, not record IDs.
territory selects the named territory. territoryAndSubordinates also includes territories below it. The affected users depend on the current hierarchy and territory memberships, not just the stored selector text. The active model and named territory therefore matter when interpreting the same rule in another org.
Selector availability is conditional
roleAndSubordinates includes subordinate roles and can include portal accounts below them. It 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. It is not interchangeable with roleAndSubordinatesInternal.
SharedTo is reused by several metadata structures, so its exposed fields are not universally valid for this rule. In particular, guestUser is restricted to SharingGuestRule. The queue selector applies only to lead, case, and custom-object sharing rules.
Administrators need View Setup and Configuration to access sharing-rule configuration and Manage Sharing to edit it. These administrative permissions are separate from the record access granted to recipients.
Deployment and Retrieval
The deployable parent container is SharingRules, identified by the object's API name. Its metadata file is stored in the sharingRules directory with the object name and the .sharingRules suffix, such as Account.sharingRules. Territory-based rules appear inside that file as sharingTerritoryRules entries, each with its own fullName.
Do not confuse the object's container identity with the contained rule's name. Also, do not attempt to create SharingBaseRule directly; it supplies inherited settings rather than a directly creatable component.
The SharingRules container supports wildcard selection in package.xml and operations covering all sharing rules in an org. Manual sharing rules are excluded from metadata retrieval, deletion, and deployment. The sharing-rule manifest examples illustrate member selection, but type-scoped operations have a documentation conflict described below.
For a rule that uses territory selectors, interpret the stored names against the destination org's active territory model and territory hierarchy. Dependencies depend on the selectors actually present; a rule sharing from a territory to a role does not have the same population references as one sharing between territories.
Relationships
Population references are nested under sharedFrom and sharedTo. They describe possible selector connections, not a requirement that every rule depend on every listed type. SharedTo is the reusable selector structure, while SharingOwnerRule and SharingBaseRule supply inherited fields.
References
-
Group:allCustomerPortalUsers,allInternalUsers,allPartnerUsers,channelProgramGroup,channelProgramGroups,group. These select groups, broad user populations, or channel-program populations. -
Role:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
Queue:queue, subject to the lead, case, and custom-object restriction. -
TerritoryModel:territory,territoryAndSubordinates. Each stored value also identifies a territory within the model.
Referenced By
-
SharingRules:sharingTerritoryRules, the collection containing the rule.
Documentation Inconsistencies
The SharingRules reference gives conflicting guidance on type-scoped retrieval, deletion, and deployment. Its prose says these operations cannot be performed by sharing-rule type, but its manifest example selects SharingCriteriaRule and SharingOwnerRule by type.
That example does not establish equivalent support for SharingTerritoryRule. Container wildcard support should not be treated as proof that territory-only retrieval, deletion, or deployment works in the same way.
Reported Issues
- A deployment failed with "Component type not permissible in destination Organization" in a 2016 report involving criteria-based sharing rules. An unaccepted answer proposed checking the manifest's rule type and object-qualified member name, using the pattern
ObjectAPIName.SharingRuleName. Its example also includedAccount.*underSharingTerritoryRule. This was proposed guidance, not a confirmed territory-rule fix, and it does not resolve the documentation conflict above. See the deployment report and proposed manifest correction.
Common Questions
Where is SharingTerritoryRule stored?
It is contained in the object's SharingRules file under sharingTerritoryRules. For example, account rules are stored in sharingRules/Account.sharingRules. The parent is identified by the object name; each rule has its own fullName.
What value goes in a territory sharing selector?
For Sales Territories, use modelName.territoryName, with the active territory model's API name and the territory's API name. Do not use a record ID. This applies to both source and recipient territory selectors.
Can a territory-based sharing rule share records with a role?
Yes. sharedFrom identifies the source record owners, while sharedTo identifies recipients. A territory-based rule can use a role as its recipient population.
Does account accessLevel also set case, contact, and opportunity access?
No. accessLevel controls the primary account records. The three fields in accountSettings separately control associated-case, contact, and opportunity access, each using None, Read, or Edit.
Can I retrieve or delete only SharingTerritoryRule components?
The documentation is inconsistent about operations scoped to a sharing-rule type. Its type-scoped manifest example covers criteria-based and owner-based rules, not territory-based rules. It therefore does not establish equivalent support for SharingTerritoryRule.