How to fix TERRITORY2_NOT_ENABLED in Salesforce deployments
A deployment includes Territory2 metadata, but Enterprise Territory Management isn't turned on in the target org.
Surfaces during: metadata deploy validation, before any DML runsWhat it means
TERRITORY2_NOT_ENABLED means a deployment carries Territory2 metadata, territory models, territory rules, or related references, into an org where Enterprise Territory Management hasn't been enabled. The feature has to be turned on in Setup before Salesforce will accept any of that metadata, regardless of how clean the deployment itself is.
Enterprise Territory Management is a feature flag Salesforce enables through Setup (or a support case, on some editions), not something the Metadata API can turn on as part of a deploy, so this is always a manual, one-time prerequisite rather than something a fix in your metadata can resolve.
Common causes
The fix
- Enable Enterprise Territory Management in the target orgTurn the feature on in Setup before attempting to deploy Territory2 metadata into that org.
- Add the feature to scratch org definitionsInclude Territory Management in the features list of scratch-org-def.json so every new scratch org has it enabled from creation.
{ "edition": "Enterprise", "features": ["TerritoryManagement2"] } - Strip Territory2 references for orgs that don't use territoriesExclude territory metadata from deployments targeting environments that intentionally don't use Enterprise Territory Management.
How Serpent prevents this
Serpent's scratch org definitions are version-controlled the same way metadata is, so the Territory Management feature can be baked into every fresh org a task provisions instead of being enabled by hand after the fact. See the Salesforce deployment error library.

Prevention
Related errors
TERRITORY2_NOT_ENABLED, answered
Start free. No credit card, no install, no commitment.
Set up in under 15 minutes. No DevOps hire needed.
