Enterprise Territory Management – Key Notes

How to use Apex based sharing to share opportunity using Territories

  • Enterprise Territory management is used to share Account and its related opportunity and Cases.
  • Account can have multiple Territories.
  • User can have multiple Territories
  • Opportunity can have only 1 Territory. Think about it – If Opportunity allowed to have multiple Territory, how revenue would be split between multiple Territory and what would be business rules ?
  • Territory enables “My Territories” and “My Team’s Territory” filter in Account and Opportunity list View.
  • While creating Territory, we can decide access to Account, Opportunity and Case. Depending on OWD, access can be private, read only and read write.
  • Enterprise Territory Management does not support overlay forecast unlike Roles. However we can create report on Opportunity split object.
  • Overlay forecast (Revenue sharing) is not supported because Opportunity can have only one territory and therefore only 1 revenue maker.
  • Maximum Territory that can be defined is around 99k unlike maximum role 10k.
  • Custom Field (but not lookup) can be created in Territory2 object.
  • Territory related list appears on user and Account records.
  • You cannot create lookup to Territory objects.
  • Territory to Opportunity can be assigned using Apex class plugin

Enable Territory based Forecast

  1. Mark user as “Allowed Forecast”
  2. Add user as Territory Team member
  3. Add user as Forecast Manager in Territory

Apex Based Sharing of Opportunity using Territory

For Apex based sharing, we use user of public group Id to share record. If we want to share Opportunity using Territory then there is quick code for that. If we click on manual share button on Opportunity, it will show an option to choose between user, public group, territory and territory with subordinates.

There is no clear documentation, but what I found that when we share using Territory, Salesforce internally creates public group for that territory and assigns that public group to Opportunity.

So, first step is to find public group created for territory. Below code showcase how it can be done.

References :

Enterprise Territory Management – Auto Account Assignment using Apex

Use Apex code to auto assign Accounts on basis of Enterprise Territory Assignment rules

Using Territory Management in Salesforce, we can auto assign territories to Account and give access to users working in common region. When we create Account, Territory Assignment rules automatically runs. On Account update we have a checkbox on page layout allowing to run Territory rules. However, Lightning experience does not support Territory Assignment checkbox yet on page layouts.

Unfortunately, Apex also does not support Account Assignment using Territory rules. Only way left is to use Salesforce API. Question is, just to run Enterprise Territory Management rules, should we import WSDL and convert it to respective Apex classes ? There must be some better way.

Then I remembered this article which I wrote around 5 years back. Instead of importing WSDL into Salesforce and converting it to Apex classes, we can take help of SOAP UI to find the request format and using HttpRequest, we can simulate request. Continue reading “Enterprise Territory Management – Auto Account Assignment using Apex”