From the Opportunity Territory Assignment section, you can enable a more detailed filter when setting up territory management for Opportunities. The default OppTerrAssignDefaultLogicFilter Apex class can be found in the documentation (see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_TerritoryMgmt_OpportunityTerritory2AssignmentFilter.htm) and is out of scope for this book (ask a developer to help you with the setup).
Each territory has its own default values that are inherited by the parent territories above it, as shown in the following screenshot:
A territory contains assigned accounts and users.
Remember that you can create up to 1,000 territories per model for Developer Edition and Enterprise Edition organizations, while for Unlimited and Performance organizations, you can ask Salesforce support to let you have up to 99,999 territories (more than 20,000 will need a deeper inspection for approval).
The first way you can assign an account to a territory is by using rules that, based on the account’s characteristics, can decide whether an account belongs to a given territory or not. These rules apply on account creation and are updated if the Territory Model is in an active state:
To create a new rule, go to the territory settings page, scroll down to the Assignment Rules Assigned to This section, and click the New button:
A rule consists of field conditions (for example, Country equals Italy, and Country equals Spain) that define the account fields to which assignment is based on, the possibility to assign the same rule to the child territories, and the active flag to enable this rule.
Can we assign to child territories? The answer is yes. First, define a generic rule that matches the different territories (for example, Country equals Italy, Country equals Spain, and Country equals Greece, which identifies southern Europe countries) that is used in the Southern Europe territory and then create a territory-specific rule in each child country for internal regions (for example, for Italy, we can have Region equals Sardinia, Region equals Sicily, and Region equals Tuscany). Finally, create specific grand-children territories depending on the postal code values you received.
Remember not to use the same rule on a child if you are already using it on a parent territory. Moreover, if your organization is using country and states picklists, use the contains operator and not the equals operator.
A territory can have up to 15 assigned rules.
You can exclude an account from the territory rules calculation by setting up the Exclude from territory assignment rules flag when updating the record (it is hidden by default on the page layout and its field-level security should be set to visible):
If you change a rule, you need to reassign the accounts that are part of the hierarchy manually by clicking the Run Assignment Rules button at the model level or the Run Rules link at the territory level:
From the territory setting page, you can even add an account manually. This is useful when sharing rules are not enough to identify an account:
To see all the accounts related to a given territory (if you’re using rules or manual assignment), click on the View Accounts button on the territory page.
Opportunities can be assigned to territories using an Apex filter (as shown earlier), but you can do this manually as well by using the Territory field and checking the Exclude from the territory assignment filter logic checkbox (they should be placed on the opportunity layout if needed):
Why is this necessary? Accounts can span multiple territories, and so there is a need to clarify where opportunities have been assigned.
Users can be associated with territories if we use the Manage Users button in the Assigned Users section of the territory setup page. Using the UI, you can assign up to 1,950 users to the territory. If you have a wider audience per territory, you should use APIs (for example, Data Loader; see the UserTerritory2Association object’s details at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userterritory2association.htm).
You can even define territory roles for users that have been assigned to a given territory. Let’s go through this now:
- To define roles, you need to switch to Salesforce Classic (at the time of writing, that is, in Spring 2019), click on Setup | Customize | User Territory Associations | Fields, and look for the Role in Territory field:
2. Define your roles (here is an example):
3. Then, go back (in Classic or Lightning Experience) to the territory page and go to the Assigned Users section. From here, it is possible to edit the user’s role within the territory:
You can even define whether a user is a forecast manager. This option is used in opportunity forecasts so that a user can roll data up or down their territory hierarchy (and even adjust and view forecast data).