Salesforce Bulk API

Bulk query jobs for extracting large datasets from Salesforce.

Operations

OperationDescription
createCreate a bulk query job.
getGet job status.
get_resultsDownload query results as Arrow RecordBatch.
abortAbort a running job.
deleteDelete a job.

Configuration

- salesforce_bulkapi_query_job:
    name: export_accounts
    operation: create
    credentials_path: /etc/salesforce/credentials.json
    query: "SELECT Id, Name, Industry FROM Account"

Fields

FieldTypeDefaultDescription
namestringrequiredTask name.
operationstringrequiredcreate, get, get_results, abort, delete.
credentials_pathstringrequiredPath to Salesforce credentials.
querystring/resourceSOQL query (for create).
parametersmapValues bound to :name in the query (for create). See Query parameters.
query_operationstringqueryquery or queryAll (includes deleted/archived).
content_typestringcsvOutput format.
column_delimiterstringcommaCSV delimiter: comma, tab, semicolon, pipe, caret, backquote.
line_endingstringlfLine ending: lf or crlf.
job_idstringJob ID (for get, get_results, abort, delete). Supports templating.
batch_sizeint10000Records per result page and per Arrow RecordBatch (for get_results).
has_headerbooltrueFirst row is header.
depends_onlistUpstream task names.
retryobjectRetry configuration.

Output

Format: JSON / Arrow RecordBatch (for get_results)

What event.data contains depends on the operation:

  • create / get / abort: Salesforce QueryJobInfo object (includes id, state, operation, query).
  • get_results: Arrow RecordBatch — each row from the query results becomes a record. Reads every result page, batch_size records at a time, retrying a failed page on its own so no page is emitted twice.

Result types

get_results types each column from the Salesforce describe of the job’s object, so types match the fields rather than the values in them:

Salesforce field typeArrow type
booleanBoolean
int, longInt64
double, currency, percentFloat64
dateDate32
datetimeTimestamp (milliseconds, UTC)
anything elseUtf8

A relationship column such as Owner.Name is typed from the related object. Columns through a polymorphic relationship, fields the describe doesn’t list, and all columns when has_header is false, are Utf8. The column delimiter is read from the job.

  • delete: {job_id, deleted: true}.

Example: Create job and get results

flow:
  tasks:
    - generate:
        name: trigger
        cron: "0 2 * * *"

    - salesforce_bulkapi_query_job:
        name: create_job
        operation: create
        credentials_path: /etc/salesforce/credentials.json
        query: "SELECT Id, Name, Industry FROM Account WHERE LastModifiedDate = TODAY"

    - salesforce_bulkapi_query_job:
        name: get_results
        operation: get_results
        credentials_path: /etc/salesforce/credentials.json
        job_id: "{{event.data.id}}"