When I tried to add territories field in soql

 list<Account> soql=[select id,name,Rating,Territories from account Where ownerid!=:UserInfo.getUserId()];

I ma getting following error.

No such column 'Territories' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 29

I could see the Territories field and when I try to get the values error coming.

What is the steps that I need to do..


"Territories" appears to be a field but actually is something else (similar to how Billing / Shipping Address field can't be queried because it really consists of 5 inner fields and how Contact Name = Salutation + First Name + Last Name).


You'll have to query through the sharing table AccountShare, then to Group (of a specific type) and then to Territory.

I don't have an org with Territories enabled handy at the moment to try actual queries but these boards posts might give you some ideas:



RowCause in AccountShare should be 'Territory Management','Territory' or 'Territory Manual', find the group id => go to group definition => find RelatedToId => that'll be the Territory Id. It's messy and you might be able to cut some corners with subqueries/parent queries but the whole setup is painful to retrieve with SOQL...

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.