Overview
The following operations allow you to work with queries. Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with queries, see Sample configuration.
Operation | Description |
---|---|
query | Retrieves data from an object. |
queryMore | Retrieves additional data if the response is too large. |
Uses the query resource along with the explain parameter to get feedback on how Salesforce will execute your query, report, or list view. | |
listviewQueryPerformanceFeedback | Retrieves query performance feedback on a report or list view. |
Operation details
This section provides further details on the operations related to queries.
Querying records
To retrieve data from an object, use salesforcerest.query
and specify the following properties. For more information on how Salesforce queries records, see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
If you want your results to include deleted records in the Recycle Bin, use salesforcerest.queryAll
in place of salesforcerest.query
.
<salesforcerest.query> <queryString>{$ctx:queryString}</queryString> </salesforcerest.query>
Properties
queryString
: The SQL query to use to search for records.
<salesforcerest.query> <queryString>{$ctx:queryString}</queryString> </salesforcerest.query>
Sample request
Following is a sample REST request that can be handled by the query
operation. Since this is a combination of two operations, the requests for both are shown below.
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "queryString": "select id, name from Account", "registryPath": "connectors/SalesforceRest" }
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "queryString": "select id, name from Account", "registryPath": "connectors/SalesforceRest" }
Related Salesforce REST documentation
query: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
queryAll: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
Querying additional records
If the results from the query
or queryAll
operations are too large, the first batch of results is returned along with an ID that you can use with salesforcerest.queryMore
to get additional results. If you want your results to include deleted records in the Recycle Bin, use salesforcerest.queryAllMore
in place of salesforcerest.queryMore
.
<salesforcerest.queryMore> <nextRecordsUrl>{$ctx:nextRecordsUrl}</nextRecordsUrl> </salesforcerest.queryMore>
Properties
nextRecordsUrl
: The query identifier for retrieving additional results.
<salesforcerest.queryAllMore> <nextRecordsUrl>{$ctx:nextRecordsUrl}</nextRecordsUrl> </salesforcerest.queryAllMore>
Sample request
Following is a sample REST request that can be handled by the queryMore
operation. Since this is a combination of two operations, the requests for both are shown below.
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "nextRecordsUrl": "%s(nextRecordsUrl)", "registryPath": "connectors/SalesforceRest" }
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "nextRecordsUrl": "%s(nextRecordsUrl)", "registryPath": "connectors/SalesforceRest" }
Related Salesforce REST documentation
queryMore: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
queryAllMore: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
Getting feedback on query performance
To get feedback on how Salesforce will execute your query, use the salesforcerest.queryPerformanceFeedback
operation. It uses the Query resource along with the explain
parameter to get feedback. Salesforce analyzes each query to find the optimal approach to obtain the query results. Depending on the query and query filters, an index or internal optimization might be used.
<salesforcerest.queryPerformanceFeedback> <queryString>{$ctx:queryString}</queryString> </salesforcerest.queryPerformanceFeedback>
Properties
queryString
: The SQL query to use to get feedback for a query.
Sample request
Following is a sample REST request that can be handled by the queryPerformanceFeedback
operation.
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "queryString": "select id, name from Account", "registryPath": "connectors/SalesforceRest" }
Related Salesforce REST documentation
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query_explain.htm
Getting feedback on query performance in listview
For retrieving query performance feedback on a report or list view, use salesforcerest.listviewQueryPerformanceFeedback
and specify the following properties.
<salesforcerest.listviewQueryPerformanceFeedback> <listViewID>{$ctx:listViewID}</listViewID> </salesforcerest.listviewQueryPerformanceFeedback>
Properties
listViewID
: The ID of the report or list view to get feedback for a query.
Sample request
Following is a sample REST request that can be handled by the listviewQueryPerformanceFeedback
operation.
{ "accessToken":"00D280000017q6q!AQoAQOeXcp7zKo3gUdy6r064_LsJ5bYYrUn_qAZG9TtKFLPfUMRxiato.E162_2XAtCTZLFQTbNk2Rz6Zm_juSakFE_aaBPp", "apiUrl":"https://ap2.salesforce.com", "clientId": "3MVG9ZL0ppGP5UrBrnsanGUZRgHqc8gTV4t_6tfuef8Zz4LhFPipmlooU6GBszpplbTzVXXWjqkGHubhRip1s", "refreshToken": "5Aep861TSESvWeug_xvFHRBTTbf_YrTWgEyjBJo7Xr34yOQ7GCFUN5DnNPxzDIoGoWi4evqOl_lT1B9nE5dAtSb", "clientSecret": "9104967092887676680", "hostName": "https://login.salesforce.com", "apiVersion": "v32.0", "intervalTime" : "100000", "listViewID":"00B28000002yqeVEAQ", "registryPath": "connectors/SalesforceRest" }
Related Salesforce REST documentation
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query_explain.htm
Sample configuration
Following is a sample proxy service that illustrates how to connect to Salesforce with the init
operation and then use the query
operation. The sample request for this proxy can be found in the query sample request.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="query" statistics="disable" trace="disable" transports="https http"> <target> <inSequence> <property name="accessToken" expression="json-eval($.accessToken)"/> <property name="apiUrl" expression="json-eval($.apiUrl)"/> <property name="queryString" expression="json-eval($.queryString)"/> <property name="clientId" expression="json-eval($.clientId)"/> <property name="refreshToken" expression="json-eval($.refreshToken)"/> <property name="clientSecret" expression="json-eval($.clientSecret)"/> <property name="hostName" expression="json-eval($.hostName)"/> <property name="apiVersion" expression="json-eval($.apiVersion)"/> <property name="registryPath" expression="json-eval($.registryPath)"/> <property name="intervalTime" expression="json-eval($.intervalTime)"/> <salesforcerest.init> <accessToken>{$ctx:accessToken}</accessToken> <apiUrl>{$ctx:apiUrl}</apiUrl> <apiVersion>{$ctx:apiVersion}</apiVersion> <hostName>{$ctx:hostName}</hostName> <clientSecret>{$ctx:clientSecret}</clientSecret> <clientId>{$ctx:clientId}</clientId> <refreshToken>{$ctx:refreshToken}</refreshToken> <registryPath>{$ctx:registryPath}</registryPath> <intervalTime>{$ctx:intervalTime}</intervalTime> </salesforcerest.init> <log category="INFO" level="full" separator=","/> <salesforcerest.query> <queryString>{$ctx:queryString}</queryString> </salesforcerest.query> <send/> </inSequence> </target> </proxy>