Skip to main content
7 votes
Accepted

Enterprise Territory Management: Using Apex/SOQL get all accounts in UserId's territories

You want to look at ObjectTerritory2Association. Represents an association (by assignment) between a territory and an object record, such as an account. Available only if Enterprise Territory ...
Adrian Larson's user avatar
  • 151k
5 votes
Accepted

How do I mass delete Territory2 records in Apex?

How do I mass delete Territory2 records in Apex? You don't. You can use the REST or SOAP API, or an app like the Apex Data Loader, but a Territory isn't something you can automate directly in Apex ...
sfdcfox's user avatar
  • 497k
4 votes

Territory Management: run Territory Account Assignment Rules from Apex

From Territory Management: running territory assignment rules on Account edit: As of version 21 of the Force.com Apex Code Developer's Guide, there is not a way to run territory assignment rules ...
battery.cord's user avatar
  • 8,845
3 votes

Create Scratch Org with specific Territory2Settings

Based on the comment by @sfdxfox I retried the data from an org where I manually set the different values in the GUI. For future reference for anyone having this issue, here are the possible values (...
Bast's user avatar
  • 161
3 votes
Accepted

Why is Territory management not available?

Territory management is not enabled by default in Salesforce. To request territory management for your organization, contact salesforce.com. If you have already done this step and you are seeing this ...
Anudeep Gopagoni's user avatar
3 votes
Accepted

Shouldn't accounts automatically be assigned to territories when created/edited if rules match?

As it turns out, one must set the Default checkbox on the account page layout properties if you want Salesforce to re-evaluate territory assignment rules when you edit an account: By default, this ...
Swisher Sweet's user avatar
3 votes

Problems writing a Test class for the salesforce OpportunityTerritory2AssignmentFilter class

Since I can't found an OOTB test class for this anywhere, I just wrote one up real quick. Requirement in OpportunityTerritory2AssignmentFilter class: You will need to mark the inner class and its ...
Jesse Milburn's user avatar
3 votes

How To Deploy UserTerritory2Association.RoleInTerritory2 Picklist Values

Starting with version 38.0, you should be able to deploy most standard picklist fields using the "StandardFieldSet" metadata type. However, in the list of standard picklist values that are supported, ...
Lauren Rockford's user avatar
2 votes
Accepted

Create 'ObjectTerritory2Association' programatically

As per the doc, ObjectTerritory2Association Available only if Enterprise Territory Management has been enabled for your Salesforce org. Follow below path to enable Enterprise Territory Management- ...
Devendra's user avatar
  • 5,075
2 votes
Accepted

Territory2. How to delete all child territories when delete parent?

First, as you've likely discovered, you can't delete territories that have children. But there's a workaround for that. It involves exporting your data using DataLoader into a CSV file, editing the ...
crmprogdev's user avatar
2 votes
Accepted

Why is there no option to enable "Manage Territories" when editing the permissions for a profile?

Only certain licenses are allowed to access territories (and thus manage them). If you're editing permissions for a profile for a license that doesn't have access to territories then you can't enable ...
John Towers's user avatar
  • 3,873
2 votes
Accepted

Seeing all Territory data in test, but SeeAllData is False

While the documentation doesn't explicitly call it out, the documentation does say: Starting with Apex code saved using Salesforce API version 24.0 and later, test methods don’t have access by ...
sfdcfox's user avatar
  • 497k
2 votes
Accepted

How To Deploy UserTerritory2Association.RoleInTerritory2 Picklist Values

As of v39.0 these can be retrieved/deployed as Standard Value Sets. RoleInTerritory2 does not appear in the docs but it still works alright: package.xml <Package> <types> &...
Matt and Neil's user avatar
2 votes
Accepted

What's the behavior/use case of "Apply to child territories" in Enterprise Territory Management?

I think the following example from the documentation will explain fairly clearly what's happening and what it is that you're missing: Example: Rules can work together within territories and child ...
crmprogdev's user avatar
2 votes
Accepted

Old and the new Enterprise Territory Management

Territories are Account based, but Forecasts are Opportunity based. With Enterprise Territory Management (TM2), there can be many different structures to Account Territories, not all of which are ...
crmprogdev's user avatar
2 votes

How to traverse territories in Salesforce using SOQL query

I rewrote your code: // Fetch Region 3 data List<Territory2> Region3 = ([SELECT Id, Name from Territory2 WHERE Name='Region 3']); System.debug(Region3[0]); // Fetch Assigned Users to Region ...
DavidSchach's user avatar
  • 5,946
2 votes
Accepted

How to give all Sales Reps read-only on all New Opportunities, but restrict them from changing Opp Owner

Make the Opportunity Owner field on the page layout Read Only. Or you could remove their profile permission to transfer records. Or use a validation rule and have ISCHANGED(ownerId) as part of the ...
DavidSchach's user avatar
  • 5,946
2 votes

Sharing of Accounts in Enterprise Territory Management

Could it be that this user gets access to the account as the user is part of a public group with users in that public group that actually have access? Yes. That could be one of the reasons. While ...
Jayant Das's user avatar
  • 30.6k
2 votes
Accepted

Managed Package: How to get rid of dependency from Territory Management feature

Finally we've figured it out. All our code base in repository has already been cleaned up from territory dependencies. But at the same time there was some garbage left right on packaging org itself (...
wesaw's user avatar
  • 3,130
2 votes

Managed Package: How to get rid of dependency from Territory Management feature

As it's been stated before, you need to engage Partner Support. Once a managed package has a dependency on a feature, and a version with that dependency is uploaded, it cannot be removed by the ISV. ...
sfdcfox's user avatar
  • 497k
2 votes
Accepted

Invoke Opportunity Territory Assignment filter from another class

The getOpportunityTerritory2Assignments method of the OppTerrAssignDefaultLogicFilter class doesn't update the db. Instead, it returns a map of the results that you should use. Try something like this:...
gvgramazio's user avatar
1 vote
Accepted

How to mass delete manually assigned accounts in territory management?

Set<Id> accountIds = new Set<Id>(); List<ObjectTerritory2Association> accountAssociations = [ SELECT Id, AssociationCause, ObjectId, SobjectType FROM ...
Vlad Khrapski's user avatar
1 vote
Accepted

Is it possible to perform upsert operation on UserTeritorry2Association?

No, it's not possible. As the documentation for UserTerritory2Association states: Supported Calls create(), delete(), describeSObjects(), query(), retrieve() As such, you can only create() and ...
sfdcfox's user avatar
  • 497k
1 vote

Create Scratch Org with specific Territory2Settings

There is a further bit of documentation, just in a different place. However, it seems to also be incomplete. Your best option is to retrieve these settings from an existing org, then use those values ...
sfdcfox's user avatar
  • 497k
1 vote

Sharing of Accounts in Enterprise Territory Management

As has been stated in other answers any additional sharing is still applied with Territory Management and the most permissive wins. You can check why a user has access to an account by querying the ...
Rick Schmidt's user avatar
1 vote

Why is Territory management not available?

Solution is to contact to Salesforce Support Team and request enabling Enterprise Territory Management
Igor Vasylevskyi's user avatar
1 vote
Accepted

Leads, Territories and Dashboard filter in Lightning Experience: impossible combination?

I don't believe you'll have any luck doing this. The limitations are two-fold: Leads are not part of Territory Management as they don't have a master-detail relationship to accounts. See this idea. ...
Kris Goncalves's user avatar
1 vote
Accepted

Errors when creating unlocked package version with Apex Territory2 dependencies

You need to specify this dependency in a configuration file. The file would look like this: { "orgName": "Sample Org", "edition": "developer", "settings": { "territory2Settings": { "...
sfdcfox's user avatar
  • 497k
1 vote
Accepted

Trigger Recursion after API Callout to Run Territory Assignment Rules

There are several ways to unravel trigger recursion. Seeing as in your case, one of the steps is a managed app that you cannot touch I suggest the following: Make sure that your trigger fires only ...
AvailableName's user avatar
1 vote
Accepted

Enterprise Territory Management without Sales Cloud User License

Is it possible to setup Enterprise Territory Management without Sales Cloud User licenses effectively? Yes, I implemented Enterprise territory Management with purely only Service Cloud User ...
ebar's user avatar
  • 447

Only top scored, non community-wiki answers of a minimum length are eligible