Skip to content
Chapter

Territory

Territory

Territory comes first because the other masters point at it. A distributor's Sold To and a vendor both carry a territory code, so the tree has to be in Salesforce before either is created. Sharma Distributors is onboarded with territoryCode TER-KA-BLR-01. That code is a Territory-level row. It hangs under a Zone, and the Zone hangs under a Region.

Code Level Name Parent
TER-KA Region Karnataka none
TER-KA-BLR Zone Bengaluru TER-KA
TER-KA-BLR-01 Territory Bengaluru Central TER-KA-BLR

ERP owns the tree. Salesforce has no outbound integration for Territory_Master__c. A user creates or edits the rows in ERP, then an explicit sync posts them. Saving a territory does not call Salesforce by itself.

ERP API What it does
POST /api/territories Saves a Region, Zone, or Territory. Sync status stays Pending
POST /api/territories/TER-KA-BLR-01/geographies Adds a geography. Only a Territory-level row can have one
POST /api/territories/TER-KA-BLR-01/sync-to-salesforce Upserts the master, then creates any geographies that are not already in Salesforce

The parent has to exist in ERP before the child. On sync, ERP posts unsynced ancestors first: Region, then Zone, then Territory.

Levels ERP accepts are Region, Zone, and Territory. A Region has no parent. A Zone parent must be a Region. A Territory parent must be a Zone. Status is Active or Inactive. A blank status is stored as Active.

Geography types are State, District, City, Taluka, Pincode, and Sub-City Zone. A pincode value must be 6 digits. The sample territory carries State Karnataka, City Bengaluru, and Pincode 560025.

The JSON ERP posts is on ERP → Salesforce. What Salesforce returns is on Salesforce → ERP.

The catalogue those distributors order is the next chapter, Product.