Territory management deployment fails in cloud org due to missing custom metadata dependencies

Deploying territory models and assignments from sandbox to production fails with missing dependency error. We created a custom territory model with 15 territories organized by region and product line. The model uses custom metadata types to define territory rules (TerritoryRule__mdt) and assignment criteria (TerritoryAssignment__mdt).

SFDX deployment error:


Error: Territory2Model 'EMEA_Sales_Model'
Problem: Custom metadata type 'TerritoryRule__mdt' not found

The custom metadata types exist in sandbox and are included in our SFDX project under force-app/main/default/customMetadata/. The sfdx-project.json includes the path. We tried deploying custom metadata first, then territory models, but still get the dependency error. The missing custom metadata blocks our territory rollout. How do we properly sequence SFDX retrieve/deploy for territory models with custom metadata dependencies?

Check your SFDX project structure carefully. Custom Metadata Type definitions should be in force-app/main/default/objects/TerritoryRule__mdt/ with the object definition file. Custom Metadata records should be in force-app/main/default/customMetadata/. If the structure is wrong, SFDX won’t recognize the dependency chain and deploys in the wrong order.

I verified the structure - we have TerritoryRule__mdt.object-meta.xml in the objects folder and individual records like TerritoryRule.EMEA_North.md-meta.xml in customMetadata folder. The sfdx-project.json has both paths listed. When I deploy just the custom metadata types first using ‘sfdx force:source:deploy -m CustomObject:TerritoryRule__mdt’, it succeeds. But when I then deploy the territory model, it still claims the metadata type doesn’t exist. Is there a cache timing issue?

Territory models have strict deployment order requirements. You need to deploy in this sequence: 1) Custom Metadata Type definitions (.object-meta.xml files), 2) Custom Metadata records (.md-meta.xml files), 3) Territory Model structure, 4) Territory assignments. Try breaking your deployment into separate commands for each layer instead of deploying everything at once.

Another thing to check - are your territory model XML files explicitly referencing the custom metadata type? Territory2Model metadata should have field references like ‘TerritoryRule__mdt.Region__c’. If the reference format is wrong, SFDX can’t resolve the dependency even if the metadata type exists. Retrieve a working territory model from another org to compare the XML structure.