0

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

  • Could you post what you've tried? Is this being ran as SOQL query, formula field, etc? – Grant Oct 6 '16 at 13:40
  • <ID,userterritory> UserIdActive=new map<ID,userterritory>select ID,userid,territoryid from userterritory where territory='001A3993AA3 ' Here I am Getting UserIds.And then again i am Querying the User for User with UserType='Manager' [select id from user where id in:userID and user_type__C='Manager' – sandy Oct 6 '16 at 14:05
  • Instead of two queries i Need a one query to get user from territory with User_Type__C ='Manager' – sandy Oct 6 '16 at 14:06
0

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' 
  • but I really need Map <TerritoryId ,UserId> from territory.How can i Modify the query to get the map Of Territory Id and userid – sandy Oct 7 '16 at 4:23
  • You can initialise a map with a list. However, the map will be of type <Id,UserTerritory>. Within the map, you will be able to access the UserId from the UserTerritory object. The syntax is: Map<Id,UserTerritory> myMap = new Map<Id,UserTerritory>([soql query here]); – Caspar Harmer Oct 7 '16 at 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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