You need to sign in to do that
Don't have an account?

Invalid type: UserTerritory2Association Kindly provide me a solution for this
Hi all Am facing this issue ,

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];
system.debug('lstUserTerritory::::::'+lstUserTerritory);
for(UserTerritory ut : lstUserTerritory) {
if(lstUserTerritory != null && !lstUserTerritory.isEmpty()) {
tIds.add(ut.TerritoryId);
}
system.debug('tIds::::::'+tIds);
am getting Invalid type: UserTerritory2Association How to fix this error ?
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];
system.debug('lstUserTerritory::::::'+lstUserTerritory);
for(UserTerritory ut : lstUserTerritory) {
if(lstUserTerritory != null && !lstUserTerritory.isEmpty()) {
tIds.add(ut.TerritoryId);
}
system.debug('tIds::::::'+tIds);
am getting Invalid type: UserTerritory2Association How to fix this error ?
Greetings to you!
UserTerritory2Association will be available only if Enterprise Territory Management has been enabled for your organization.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userterritory2association.htm
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