Create a Query Job

Creates a query job.

URI: /services/data/vXX.X/jobs/query

Available since release:

This resource is available in API version 47.0 and later.

Format: application/json

HTTP method: POST

Authentication: Authorization:Bearer token

Headers: Optionally, use the Sforce-Call-Options header to specify a default namespace.

Request body

The request body specifies the query to be performed.

Bulk API 2.0 doesn’t support SOQL queries that include any of these items:

  • GROUP BY, OFFSET, or TYPEOF clauses.
  • Aggregate Functions such as COUNT().
  • Date functions in GROUP BY clauses. (Date functions in WHERE clauses are supported.)
  • Compound data, such as compound address fields, compound geolocation fields, and FIELDS(). (Instead, query the individual components of compound fields.)
  • Parent-to-child relationship queries. (Child-to-parent relationship queries are supported.)

You can also specify some optional parameters. For example:

Request parameters:

ParameterDescriptionRequired or Optional
operationThe type of query. Possible values are:
  • query—Returns data that hasn’t been deleted or archived. For more information, see query() in SOAP API Developer Guide.
  • queryAll—Returns records that have been deleted because of a merge or delete, and returns information about archived Task and Event records. For more information, see queryAll() in SOAP API Developer Guide.
Required
queryThe query to be performed.Required
contentTypeThe format to be used for the results. Currently the only supported value is CSV (comma-separated variables). Defaults to CSV. The actual separator can be a character other than a comma. The columnDelimiter parameter specifies what character to use.Optional
columnDelimiterThe column delimiter used for CSV job data. The default value is COMMA. Possible values are:
  • BACKQUOTE—back quote character (`)
  • CARET—caret character (^)
  • COMMA—comma character (,)
  • PIPE—pipe character (|)
  • SEMICOLON—semicolon character (;)
  • TAB—tab character
Optional
lineEndingThe line ending used for CSV job data, marking the end of a data row. The default is LF. Possible values are:
  • LF—linefeed character
  • CRLF—carriage return character followed by a linefeed character
Optional

Response Body

Response Parameters:

ParameterDescription
idThe unique ID for this job.
operationThe type of query.
objectThe object type being queried.
createdByIdThe ID of the user who created the job.
createdDateThe UTC date and time when the job was created.
systemModstampThe UTC date and time when the API last updated the job information.
stateThe current state of processing for the job. Possible values are:
  • UploadComplete—The job is ready to be processed and Salesforce has put the job in the queue.
  • InProgress—Salesforce is processing the job.
  • Aborted—The job has been aborted. See Abort a Query Job.
  • JobComplete—Salesforce has finished processing the job.
  • Failed—The job failed.
concurrencyModeReserved for future use. How the request is processed. Currently only parallel mode is supported. (When other modes are added, the API chooses the mode automatically. The mode isn’t user configurable.)
contentTypeThe format to be used for the results. Currently the only supported value is CSV. JunctionIdList fields and embedded lists can’t be returned.
apiVersionThe API version that the job was created in.
lineEndingThe line ending used for CSV job data, marking the end of a data row.
columnDelimiterThe column delimiter used for CSV job data.

This example creates a job that queries Accounts.

The response is: