Invalid Query Scope: MineAndMyGroups

I am trying to run the query:

SELECT Id,Name FROM ListView USING SCOPE MineAndMyGroups WHERE SObjectType='Account'

I want to retrieve only listviews that are owned by the user and were shared/assigned to the user and populate them into my picklist.

When I enter that query into queryeditor I get this error:

Name FROM ListView USING SCOPE MineAndMyGroups WHERE SObjectType='Account'
                               ^
ERROR at Row:1:Column:43
Invalid query scope: MineAndMyGroups

It works fine when I substitute “MineAndMyGroups” with “Mine”.
Am I missing any requirements or is there another way to achieve what I want?

Thanks

Answer

Update from Salesforce – confirmed that Mine_And_My_Groups scope is only valid for ProcessInstanceWorkItem

I think there’s a couple of issues here:

  1. I think the Salesforce USING SCOPE documentation is wrong, and the correct scope is probably Mine_And_My_Groups, which matches the other syntaxes e.g. My_Team_Territory.

  2. Whether it’s MineAndMyGroups or Mine_And_My_Groups, it’s either never been implemented for most/all objects (other than ProcessInstanceWorkItem) or has ceased working at some point

My rationale:

  1. I can successfully query ProcessInstanceWorkItem with USING SCOPE Mine_And_My_Groups, and in a dev org it returns Approval items assigned to me or to queues I’m a member of.1

  2. Querying in the dev console or through SOAP API gives different results depending on scope. SELECT Id FROM Case USING SCOPE MineAndMyGroups fails to execute ERROR at Row:1:Column:33 Invalid query scope: MineAndMyGroups, whereasSELECT Id FROM Case USING SCOPE Mine_And_My_Groups executes but then returns an error when retrieving results, Invalid query scope: Mine_And_My_Groups.2

  3. Similarly they are different in execute anonymous. System.debug([SELECT Id FROM Case USING SCOPE MineAndMyGroups]); returns a compile failure, using Mine_And_My_Groups compiles but returns a runtime exception, both errors are Invalid query scope: <SCOPE>

I’ve checked combinations of the following scenarios being true and false which have no effect on the behaviour:

  • A queue exists
  • A queue exists which can own the object I’m querying
  • A queue exists which I am a member of
  • A record exists which is owned by a queue

I’ve tried with the following objects: Lead, Case, ListView and managed and unmanaged Custom Objects. Even if this worked for other objects, I think there’s the potential for ListView to not be supported as it’s a crossover between data and metadata.

This might not be the only part implemented functionality in the USING clause.

1 In my current scratch org it strangely only returns approval items from my queues and not those assigned to me.

2 Interestingly this is also the case for MyGroups vs. My_Groups.

Attribution
Source : Link , Question Author : anne , Answer Author : James

Leave a Comment