as you can see in the picture, the task is simple, but instead of going one by one and manually deleting each manually assigned accounts in territory management, how would one go about deleting each block of manually assigned accounts in each territoy? Also, there is no assignment rules attached to them as well.

enter image description here


1 Answer 1

Set<Id> accountIds = new Set<Id>();
List<ObjectTerritory2Association> accountAssociations = [
    SELECT Id, AssociationCause, ObjectId, SobjectType 
    FROM ObjectTerritory2Association 
    WHERE Territory2Id = '0MI7A000000DViPWAW' AND AssociationCause = 'Territory2Manual'
for (ObjectTerritory2Association accountAssociation: accountAssociations) {
    if (accountAssociation.SobjectType == 'Account') {

Hi, Add Territory2Id to the script to delete Accounts from the territory.
Not sure why filtering by SobjectType doesn't work, but it could be done in Apex as well

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .