This question already has an answer here:

I need a query to take the name of the territory to which a user belongs I try with this

UserTerritory userT = [SELECT Id, Terrotory.Name FROM UserTerritory WHERE UserId = :currentUser LIMIT 1];

but throws this error

SELECT Id, Territory.Name ^ ERROR at Row:1:Column:12 Didn't understand relationship 'Territory' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

marked as duplicate by glls, Raul, David Reed, battery.cord, sfdcfox soql Mar 6 '18 at 16:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Because you can not use relationships with the UserTerritory object. You can query UserTerritory for the TerritoryID, and then query Territory using that ID to get the Name.

Not the answer you're looking for? Browse other questions tagged or ask your own question.