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
gkappgkapp 

Query Account Territory help!!

Is there a way to query on an account ID, and identify it's Territory Name. I know there is not an easy way for this but iam having trouble establishing relationship.

 

Thanks in advance 

SFDCRRSFDCRR

FYI: if this helps 

Territory Assignment first  refers to the Group table.

 

The Group Table contains:
Group ID
Related ID: In the case of Territory Management, Related ID refers back to the Territory ID
Type: For Territory Management, this will display Territory or Territory and Subordinates

 

Then the Group table checks the Share table.
Share Table contains:
Account ID
User Or Group ID
Account Access Level
Opportunity Access Level
Case Access Level
Contact Access Level
Row Cause: For Territory Management, this will display Territory or Territory Manual

 

The Share Table then  refers to the Account table and this is how Territory Assignment – and ultimately Territory permissions - is  applied to the Account record.

SFDCRRSFDCRR

Let me know u trying to achieve - give me the example 

gkappgkapp

Need to write a SOQL query on an account ID, and identify it's Territory Name

gkappgkapp

Ya i do have the ER diagram , iam try to perform the relationship joins & failing at it . UserorGroup id is the key between account share & group

Basically  accountshare-group-opportunityshare-opportunity-territory

SFDCRRSFDCRR

I do not have Territory in my present sandbox setup.

 

use sfexploer and you will trying querying.

 

i think u should query territory and match the account id and take the territory.

Satya.KonaSatya.Kona

Dont have sfexplorer at the moment...wrote this in a notepad, let me know if this helps..

 

select a.id, t.id from account a, accountshare ac, group g, territory t
where a.id = ac.accountid and
and ac.rowcause in ('Territory Management','Territory','Territory Manual')
and ac.userorgroupid = g.id
and g.relatedid = t.id

Meredith JenMeredith Jen
Hi,

Could anyone help me how "Territories" field on account can be pulled. I see in our instance that field is manually assigned through automation. I am not sure how that is possible. Please help me!!

Thanks. 
P R 11P R 11
Coudl you please share the steps or code that worked to meet this requirement?