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

get accounts by territory for specific user

I've been reviewing the territory management ERD and trying to get a handle on how to query for the accounts by territory assigned to a specific user.


In my controller, I'm using UserInfo.getUserId() to get the userId of the current user.


I need to get a list of accounts filtered by territory for that user. 


Looking at the ERD, it looks like I need to to query the group table, but the Ids on the group table don't have any matches to the userId, so how do I get the relevant group ids for the specific user? How do I obtain a set of ids for a specific user that can be used to query on the accountShare table that should then return a list of accounts ids that are the accounts by territory for that user? 


Am I travesing the objects correctly? I'm missing a relationship somewhere.


Thanks for any help.