Newer Version Available

This content describes an older version of this product. View Latest

USING SCOPE

The optional USING SCOPE clause of a SOQL query returns records within a specified scope. For example, you can limit the records to return only objects that the user owns or only records in the user’s territory.

With API version 32.0 and later, you can use USING SCOPE to limit the results of a query to a specified filterScope. The syntax is:

1[USING SCOPE filterScope]
filterScope can take one of the following enumeration values:
delegated
Filter for records delegated to another user for action. For example, a query could filter for only delegated Task records.
everything
Filter for all records.
mine
Filter for records owned by the user running the query.
mine_and_my_groups
Filter for records assigned to the user running the query and the user’s queues. If a user is assigned to a queue, the user can access records in the queue. This filter applies only to the ProcessInstanceWorkItem object.
my_territory
Filter for records in the territory of the user running the query. This option is available if territory management is enabled for your organization.
my_team_territory
Filter for records in the territory of the team of the user running the query. This option is available if territory management is enabled for your organization.
team
Filter for records assigned to a team, such as an Account team.
To find out what scopes an object supports, call describeSObject() (for SOAP API) or sObject Describe (for REST API). In the supportedScopes section of the object’s description, the name shows the name of the scope and the label shows an explanation of that scope. For example, the description of the Account object shows:
1"supportedScopes" : [
2      {
3         "label" : "All accounts",
4         "name" : "everything"
5      },
6      {
7         "label" : "My accounts",
8         "name" : "mine"
9      },
10      {
11         "label" : "My team's accounts",
12         "name" : "team"
13      }
14   ],

filterScope in SOQL is different from filterScope used in Metadata API.

Note