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
gowtham murugesangowtham murugesan 

Invalid type: UserTerritory2Association Kindly provide me a solution for this

Hi all Am facing this issue ,
here whats the mistake?

 set<Id> tIds = new set<Id>();
         List<UserTerritory2Association> lstUserTerritory = [SELECT Id, User.FirstName, User.LastName,Territory2.Name,Territory2Id, Territory2.Territory2Model.Name FROM UserTerritory2Association WHERE UserId =: userinfo.getUserId() and IsActive = True];

            for(UserTerritory ut : lstUserTerritory) {
             if(lstUserTerritory != null && !lstUserTerritory.isEmpty()) {

am getting Invalid type: UserTerritory2Association How to fix this error ?
Khan AnasKhan Anas (Salesforce Developers) 
Hi Gowtham,

Greetings to you!

UserTerritory2Association will be available only if Enterprise Territory Management has been enabled for your organization.

Enable Enterprise Territory Management:
  1. From Setup, enter Territories in the Quick Find box, and then select the territory settings.
  2. Click Enable Enterprise Territory Management.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas