[SalesForce] need a one query which will fetch the users from territory with (Custom Field on User User_Type__C is =’manager’

Requirment :- I need to fetch the assigned user to the territory for any account.

I have one account with territory and in that territory assigned user count is 5 and there is one user with UserType='Manager'.

I need a Single SOQL query which will fetch the user with UserType='Manager' from Territory

Best Answer

I haven't tested this, but I think using a nested sub-select in the WHERE clause will work for you. You may need to tweak, but I think this will get you close:

[SELECT Id 
 FROM User 
 WHERE Id IN 
     (SELECT UserId FROM UserTerritory WHERE Territory='001A3993AA3 ') 
     AND User_Type__c='Manager'