Territory defines a territory's position in the territory hierarchy, its record-access settings, and whether its forecast manager can manually share their own forecast. It inherits common settings from RoleOrTerritory, a shared base type that you cannot create directly.
The definition describes the territory, not a particular user's effective record access. Actual user and record assignments, the organization's sharing model, and territory defaults all matter. Also, mayForecastManagerShare is a forecast-sharing control, not a territory activation setting.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The unique API identifier, corresponding to Territory Name in the user interface. It has stricter naming rules than an unrestricted text value. |
name |
The required territory name. This is a separate element from fullName. |
parentTerritory |
References the Territory immediately above this territory in the hierarchy. |
accountAccessLevel |
Access for users in this territory to accounts assigned to the territory that are otherwise inaccessible. Allowed values are Read, Edit, and All. When account sharing is Public Read/Write, only Edit and All are valid. |
caseAccessLevel |
Access to other users' cases associated with accounts the user owns. Allowed values are Read, Edit, and None. The setting is not visible when case sharing is Public Read/Write. |
contactAccessLevel |
Access to other users' contacts associated with accounts the user owns. Allowed values are Read, Edit, and None. The setting is not visible when contact sharing is Public Read/Write or Controlled by Parent. |
opportunityAccessLevel |
Access to other users' opportunities associated with accounts the user owns. Allowed values are Read, Edit, and None. The setting is not visible when opportunity sharing is Public Read/Write. |
mayForecastManagerShare |
A boolean indicating whether the forecast manager can manually share their own forecast. It does not define a forecast hierarchy. |
Behavior and Constraints
Account access and related-record access have different documented scopes. accountAccessLevel concerns otherwise inaccessible accounts assigned to the territory. The inherited caseAccessLevel, contactAccessLevel, and opportunityAccessLevel settings concern other users' related records associated with accounts the user owns. Do not assume all four settings have the same assigned-account scope.
Read each access setting together with the object's organization-wide sharing model, which establishes baseline record access. Public Read/Write restricts the valid account-access values and hides the corresponding case and opportunity settings. Contact sharing also hides contactAccessLevel when it is Controlled by Parent.
An unset access level does not mean None. When an access-level value is unset, Salesforce uses the default configured on the Manage Territory page in Setup. Identical metadata with omitted access levels can therefore depend on different defaults in different organizations.
This defaulting behavior does not establish that omitting an element during an update clears an existing explicit value. Do not treat element omission as a documented reset procedure.
parentTerritory establishes the immediate parent in the territory hierarchy. That relationship alone does not establish assignment-rule inheritance. Likewise, enabling mayForecastManagerShare permits the forecast manager to share their own forecast; it neither activates the territory nor defines how forecasts roll up through a hierarchy.
Deployment and Retrieval
Territory components use the .territory file suffix and reside in the territories directory of the corresponding package directory. Use Territory as the type name in package.xml. The type supports the * wildcard for selecting its components in the manifest.
The API identity in fullName must be unique, begin with a letter, and contain only alphanumeric characters and underscores. It cannot contain spaces or consecutive underscores, and it cannot end with an underscore. The separate name element is required.
For a deployment into an organization with Public Read/Write account sharing, Read is not a valid accountAccessLevel; only Edit and All are valid. When comparing retrieved definitions across organizations, account for omitted access levels that depend on each organization's Manage Territory defaults.
For an API identity or hierarchy change, distinguish child-territory references from report-filter references. A child territory uses parentTerritory, while a report uses territoryHierarchyFilter. These connections do not, by themselves, establish a mandatory deployment sequence.
Relationships
A territory can reference another territory as its parent and can itself be referenced by child territories. Reports have a separate connection through their territory hierarchy filter. Inheritance from RoleOrTerritory supplies shared fields; it is not a separately creatable component dependency.
References
-
Territory:parentTerritory.
Referenced By
-
Report:territoryHierarchyFilter. -
Territory:parentTerritory.
Reported Issues
-
Apex tests involving territory setup can fail with
MIXED_DML_OPERATION. A 2013 report described this when tests created users, territories, territory assignments, and accounts together. This is a data manipulation language (DML) issue involving setup and non-setup records, rather than a territory access-level error. A separate 2018 answer reported usingSystem.runAsblocks for mixed DML in tests. See the territory implementation report and the test mixed-DML discussion. -
Restoring account data may not restore manually maintained territory sharing. In the same 2013 implementation report, an accidental production data-migration run removed sharing information. The author reported restoring accounts and contacts but being unable to recover the sharing information from the Recycle Bin. This concerned sharing data, not a documented procedure for deleting or restoring
Territorymetadata. See the sharing-loss report. - Running assignment rules reportedly removed accounts that appeared to match the criteria. In a 2014 discussion involving billing country and state-code criteria, manually saving an account assigned it to the territory, but running the rules removed it. The question author reported that adding full state-name criteria alongside state-code criteria resolved their case, while leaving the underlying cause unexplained. Treat that as a case-specific workaround, not a requirement to duplicate address criteria. See the assignment-rule mismatch discussion.
-
A direct-territory account query can miss the descendant coverage an administrator expects. In answers from 2013 through 2015, community members described querying runtime assignment data through
UserTerritory, territory-relatedGrouprecords, andAccountShare, rather than relying on the metadata definition. An expanded example explicitly collected child territory IDs before querying shares when descendant accounts were needed. These are runtime record-query patterns, not additional metadata references. See the account-by-territory query discussion.
Common Questions
How do I retrieve all Territory metadata components?
Use Territory as the type name and * as the member selection in package.xml. Components use the .territory suffix in the territories directory.
Does omitting an access-level element set it to None?
No. An unset access level uses the default on the Manage Territory page in Setup. That rule does not establish that omission during an update clears a previously explicit value.
Why is contactAccessLevel not visible?
The setting is not visible when contact sharing is Public Read/Write or Controlled by Parent. Case and opportunity access settings are also not visible when their corresponding object's sharing model is Public Read/Write.
What references should I check before changing a territory's name or parent?
For an API identity or hierarchy change, check child Territory components that use parentTerritory and Report components that use territoryHierarchyFilter. The API identifier is fullName, corresponding to Territory Name in the user interface; name is a separate required element.
Does mayForecastManagerShare activate a territory?
No. It controls whether the forecast manager can manually share their own forecast. It is not an activation setting and does not define a forecast hierarchy.