function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Puneeth KumarPuneeth Kumar 

sObject type 'UserTerritory2Association' is not supported.

Hi All,

I got piece of code in my test class which uses objects belonging to Territory management 2.0, was unable to initialize a variable of type 'UserTerritory2Association' . I see there are diference in objects from TM --> TM 2.0, acoordingly I have changed my code but still the same error persists. For refernece attaching screenshot as well as error. Please advice.

I have the error in line 75
User-added image

Error: sObject type 'UserTerritory2Association' is not supported.
 
Best Answer chosen by Puneeth Kumar
NagendraNagendra (Salesforce Developers) 
Hi Puneeth,

Enterprise Territory Manage uses different objects.

Territory2
UserTerritory2Association
ObjectTerritory2Association
Territory2Model
RuleTerritory2Association

Kindly modify your code as below:
List<UserTerritory2Association> utList = new List<UserTerritory2Association>([SELECT Id, IsActive, RoleInTerritory2, Territory2Id, UserId from UserTerritory2Association]); system.debug(utList);
For more information please refer to the below link:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userterritory2association.htm

Kindly mark this as solved if it helps you.

Best Regards,
Nagendra.P



 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Puneeth,

Enterprise Territory Manage uses different objects.

Territory2
UserTerritory2Association
ObjectTerritory2Association
Territory2Model
RuleTerritory2Association

Kindly modify your code as below:
List<UserTerritory2Association> utList = new List<UserTerritory2Association>([SELECT Id, IsActive, RoleInTerritory2, Territory2Id, UserId from UserTerritory2Association]); system.debug(utList);
For more information please refer to the below link:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userterritory2association.htm

Kindly mark this as solved if it helps you.

Best Regards,
Nagendra.P



 
This was selected as the best answer
Puneeth KumarPuneeth Kumar
Thanks Nagendra, I have already solved it. And it the same solution as you provided.