Skip to main content
 here we are using enterprise territory management and am getting this error "Invalid type: UserTerritory2Association" for this below code 

 

UserTerritory2Association lstUserTerritory = [SELECT Id, User.FirstName, User.LastName,Territory2.Name,Territory2Id, Territory2.Territory2Model.Name

 

      FROM UserTerritory2Association WHERE UserId =: userinfo.getUserId() and IsActive = True];

 

        if(lstUserTerritory != null && !lstUserTerritory.isEmpty()) {

 

             for(UserTerritory2Association t : lstUserTerritory) {

 

                   TerritoriesList.add(new SelectOption(t.Territory2Id,t.Territory2.Name));

 

               }

 

        }

 

 How to get the UserName and territory name assign to user in  query?
1 respuesta
  1. 11 sept 2019, 08:29
    Hi Mohankumar,

     

    Can you try below code - 

     

    List<UserTerritory2Association> lstUserTerritory = [SELECT Id, User.FirstName, User.LastName,Territory2.Name,Territory2Id, Territory2.Territory2Model.Name

     

          FROM UserTerritory2Association WHERE UserId =: userinfo.getUserId() and IsActive = True];

     

            if(lstUserTerritory != null && !lstUserTerritory.isEmpty()) {

     

                 for(UserTerritory2Association t : lstUserTerritory) {

     

                       TerritoriesList.add(new SelectOption(t.Territory2Id,t.Territory2.Name));

     

                   }

     

            }

     

    Thanks!
0/9000