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
markdalius_devmarkdalius_dev 

Get a list of a user's assigned territories in Apex using SOQL

I'm trying to get at the territories that a user is associated with. I'm guessing the code is something like:

 

user.territory__r.territory_name

 

The use case is, I'm importing external data into a custom object, and there's going to be a field called "territory". I want to build a dashboard that displays the results of a SOQL query that does something like "select * from dashboard_table where user.territory = dashboard_table.territory".

 

I'm not really using the territory management feature here; I'm essentially trying to get a string version of the user's territory and use that string as a primary key (I'm aware of the implications around duplicates, etc.) to match on a record. Can anybody help?