0

I was wondering if someone could explain this to me. I am currently working in an org with Territory Management (1.0) enabled and I am trying running queries but getting weird results.

When I run a query like this:

Select Id From AccountShare WHERE UserOrGroup.Type = 'Territory'

I get no results back.

However, if I do this:

Select Id From Group WHERE Type = 'Territory' //Take an Id from this result set

Select Id,UserOrGroup.Type From AccountShare WHERE UserOrGroupId =: fromPreviousResult

I get records back. Now the weird part is, UserOrGroup.Type returned in the AccountShare query says Queue even though the Id from the Group query is clearly a type of Territory. Is there something I am missing

0

UserOrGroup field is a polymorphic reference field most probably that is the reason. When using a polymorphic field; polymorphicfield.type in where clause returns the object type.

so

WHERE UserOrGroup.Type = will return either User or Group

so your query should be like below:

SELECT Id FROM AccountShare WHERE UserOrGroup.Type='Group' AND UserOrGroupId IN ( Select Id From Group WHERE Type = 'Territory' )

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_filtering_polymorphic_relationships.htm

4
  • 1
    I'm not understanding why Queue would be returned. It's not a Queue to begin with – Bryan Anderson May 7 '20 at 14:29
  • Do you have a sharing rule that shares account's with a queue? – Mert YALTI May 7 '20 at 14:41
  • Queues are not supported for accounts. Also this is about Territory Management – Bryan Anderson May 7 '20 at 15:02
  • Correct they are not supported. Well I cannot think of anything else. – Mert YALTI May 7 '20 at 15:13

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.