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
jojoforcejojoforce 

User and UserTerritory Join?

Is there a way to show the Territory.Name field and the User.Firstname, User.LastName via SOQL?

 

I tried the following code, but it doesn't seem to work. Thanks in advance for any help.

 

SELECT TerritoryId.Name, UserId.FirstName,UserId.LastName FROM UserTerritory

 

Best Answer chosen by Admin (Salesforce Developers) 
jojoforcejojoforce

I agree. I was able to get this to work though. I used the Map<String, Object> and basically used the Key Value as their join condition.

 

Please note: This is just partial coding... but you get the idea. 

 

Map<String, Object> o1
Map<String, Object> o2



o1.put(key1, ObjectOneRecord);
o1.put(key2, ObjectOneRecord);

o2.put(key1, ObjecTwotRecord);
o2.put(key2, ObjectTwoRecord);

 



 

Something like that.. and then for calling them I used something like the below to be able to display the record\

 

for(Object3 obj : select id, key, name from Object3) { 

o1[obj.key].Field1
o2[obj.key].Field2

}

 

All Answers

RajiRaji

Hi,

 

can't access userid.lastname and userid.firstname from Userterritory. we can get the userid and need to Query again .

 

 

Regards,

VNath.

 

 

jojoforcejojoforce

I agree. I was able to get this to work though. I used the Map<String, Object> and basically used the Key Value as their join condition.

 

Please note: This is just partial coding... but you get the idea. 

 

Map<String, Object> o1
Map<String, Object> o2



o1.put(key1, ObjectOneRecord);
o1.put(key2, ObjectOneRecord);

o2.put(key1, ObjecTwotRecord);
o2.put(key2, ObjectTwoRecord);

 



 

Something like that.. and then for calling them I used something like the below to be able to display the record\

 

for(Object3 obj : select id, key, name from Object3) { 

o1[obj.key].Field1
o2[obj.key].Field2

}

 

This was selected as the best answer