Get Results for a Query Job

Gets the results for a query job. The job must have the state JobComplete.

Syntax

URI
/services/data/vXX.X/jobs/query/queryJobId/results
1/services/data/vXX.X/jobs/query/queryJobId/results
2   ?locator=locator
3   &maxRecords=maxRecords
Available since release

This resource is available in API version 47.0 and later.

Formats
CSV
HTTP methods
GET
Authentication
Authorization: OAuth sessionId
Request parameters
Parameter Description Required or Optional
queryJobId The ID of the query job. Required
locator Gets a specific set of results.

If this is omitted, the request returns as many rows as can be listed. If there are more results than can be listed, the Sforce-Locator header contains a locator value to get the next set of results.

See Rules and Guidelines.

Optional
maxRecords The maximum number of records to retrieve per set. The request is still subject to the size limits.

If you are working with very large query result sets, you may experience a timeout before receiving all the data from Salesforce. To prevent a timeout, specify the maximum number of records your client is expecting to receive by in the maxRecords parameter. This splits the results into smaller sets.

Optional
Response Body
If the request is successful, the status code is 200 (OK) and the request body contains the results of the job’s query. For example:
1"Id","Name"
2"005R0000000UyrWIAS","Jane Dunn"
3"005R0000000GiwjIAC","George Wright"
4"005R0000000GiwoIAC","Pat Wilson"
5...
Response For an Unsuccessful Request
If the request fails, the status code is 204 (No Content).
Response Headers
Header Description
Sforce-NumberOfRecords The number of records in this set.
Sforce-Locator

The URI to get the next set of results. See Rules and Guidelines.

If there are no more results, this header is null.

Example

The following retrieves the results for the job with ID 750R0000000zxr8IAA.
1curl --include --request GET \
2--header "Authorization: OAuth 00DR00000000nd2aAQ8AQORpU.gf72HWKXAOkAcjOhYvBfvXiqgkMcERVkxSauharjcilr8BxJRjou
3E5mopL2TvHflPMtRd4.FFl63Yuq5pmhPaa1" \
4--header "Accept: test/csv " \
5--header "Content-Type: application/json" \
6"https://instance.salesforce.com/services/data/v46.0/jobs/query/750R0000000zxr8IAA/results"
The response body is:
1HTTP/1.1 200 OK
2Sforce-NumberOfRecords: 500
3Sforce-Locator: 1000
4
5
6"Id","Name"
7"005R0000000UyrWIAS","Jane Dunn"
8"005R0000000GiwjIAC","George Wright"
9"005R0000000GiwoIAC","Pat Wilson"
10...

The Accept header must match what was specified when the job was created. Currently only text/csv is supported.

Note

Rules and Guidelines

  1. Use /services/data/vXX.X/jobs/query/queryJobId/results to get the first set of results for the job.
  2. If there are more results than can be listed, the Sforce-Locator response header will be non-null. Set the locator to that value to get the next set of results.

    For locator, only use the value from the Sforce-Locator header. Do not try to guess what it will be. How this parameter is evaluated is subject to change.

    Note

  3. Repeat this process until the Sforce-Locator header is null. That set is the last set of results.