Print this page

How to mass-delete Territories?

Knowledge Article Number 000025422
Description Within Salesforce Territory Management, territories can easily be removed manually by doing Setup | Manage Territory | Hierarchy & then click on [Del] for a selected bottom-level territory. But what about deleting large numbers of territories at one time?

The Data Loader can help with mass territory deletion, but because Salesforce territories cannot be deleted if they have child territories, your deletion must be organized to delete bottom-level territories first, working up through the territory tree. But how can this be done?

Fist use Data Loader to export the Territory data from the Territory Object and prepare an Excel CSV file listing all the territories you want to remove from the TM Hierarchy.

Choose Show all objects to select Object=Territory. Then include fields: Id, Name, ParentTerritoryId.

IMPORTANT: Either use SOQL query in your Data Loader export or edit the CSV file later to EXCLUDE territories you don't want to delete.

Next, there are two options for removing the exported territories choose ONE:

METHOD 1.  Organize your CSV data file whereby the territories are listed sequentially from the lowest node (hierarchy level) to highest node (hierarchy level). Using the data export from the Territory object and some manipulation in Excel can help with this sequencing.  Then in Data Loader use the Settings menu to change your Data Loader Batch size set to 1 (this is so that each row in the file gets processed one at a time). Then use Data Loader's Delete function with Object Territory (Show all objects) with your sorted CSV file to delete the territories. The Id field identifies the correct territories to delete.

METHOD 2.  Or you can skip the step of sorting your CSV file and territories listed in that file can still be deleted simply by running Data Loader Delete multiple times until all child and parent territories are deleted. Depending on the order of territories in the CSV file, if the lower nodes are sequenced before the parent nodes, they will be deleted. The Data Loader error file for each pass will contain the remaining Hierarchy records that were not successfully processed.  Continue to process the territories listed in each new error file, iteratively, and it will whittle away at the hierarchy tree until all the Territories are deleted.

promote demote