Bulk API 2.0: ingest jobs (insert, update, upsert, delete, hardDelete from CSV) and query jobs (SOQL results as CSV) for data volumes past what ::salesforce::composite handles comfortably.

Ingest: create-ingest-job → upload-job-data (one CSV upload per job, up to 150 MB) → close-job → poll get-ingest-job until is-job-finished → successful-results / failed-results / unprocessed-records. ingest does the first three steps in one call.

Query: create-query-job → poll get-query-job → query-results, following locator while it is non-null.

Jobs run asynchronously on Salesforce's side and hot-std has no sleep, so poll from a scheduled function, a later event, or a task whose retry policy supplies the delay: poll-ingest-job and poll-query-job return an Err until the job is finished, which is exactly what a retrying task needs.

Values

FINISHED_STATES

FINISHED_STATES: Vec [
  "JobComplete",
  "Failed",
  "Aborted"
]

INGEST_OPERATIONS

INGEST_OPERATIONS: Vec [
  "insert",
  "update",
  "upsert",
  "delete",
  "hardDelete"
]

Functions

abort-ingest-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

PATCH /jobs/ingest/{id} with state: Aborted - Abort an open or in-progress ingest job.

Example

::salesforce::bulk/abort-ingest-job("750R0000000000A")

abort-query-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

PATCH /jobs/query/{id} with state: Aborted - Abort a running query job.

Example

::salesforce::bulk/abort-query-job("750R0000000000A")

build-ingest-job-body

fn (object: Str, operation: Str, options: Map): Map

The create-ingest-job body. operation is one of insert, update, upsert, delete, hardDelete; options: external-id-field (required for upsert), line-ending (LF default or CRLF), column-delimiter (COMMA default, TAB, PIPE, SEMICOLON, CARET, BACKQUOTE), assignment-rule-id. Unset options are omitted. Returns an Err for an unknown operation or an upsert without an external id field.

Example

::salesforce::bulk/build-ingest-job-body("Contact", "insert", {})
// {object: "Contact", operation: "insert", contentType: "CSV"}

is-err(::salesforce::bulk/build-ingest-job-body("Contact", "upsert", {}))  // true

build-query-job-body

fn (soql: Str, options: Map): Map

The create-query-job body. options: include-deleted (operation queryAll), line-ending, column-delimiter. Unset options are omitted.

Example

::salesforce::bulk/build-query-job-body("SELECT Id FROM Contact", {include-deleted: true})
// {operation: "queryAll", query: "SELECT Id FROM Contact"}

close-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

PATCH /jobs/ingest/{id} with state: UploadComplete - Tell Salesforce the data is in so processing starts. Returns the job.

Example

job ::salesforce::bulk/close-job("750R0000000000A")
job.state

create-ingest-job

fn (object: Str, operation: Str): Map
fn (object: Str, operation: Str, options: Map): Map
fn (object: Str, operation: Str, options: Map, opts: Map): Map

POST /jobs/ingest - Open an ingest job. See build-ingest-job-body for the options. Returns the job (id, state: "Open", ...).

Example

job ::salesforce::bulk/create-ingest-job("Contact", "upsert", {external-id-field: "External_Id__c"})
job.id

create-query-job

fn (soql: Str): Map
fn (soql: Str, options: Map): Map
fn (soql: Str, options: Map, opts: Map): Map

POST /jobs/query - Start an asynchronous SOQL export. options: include-deleted, line-ending, column-delimiter.

Example

job ::salesforce::bulk/create-query-job("SELECT Id, Email FROM Contact")
job.id

csv-cell

fn (value: Any): Str

Render one CSV cell: null → empty, Bool/number → text, and quote (doubling inner quotes) when the value holds a comma, quote, or line break. Exposed for testing.

Example

::salesforce::bulk/csv-cell("a,b")  // "\"a,b\""
::salesforce::bulk/csv-cell(null)  // ""
::salesforce::bulk/csv-cell(true)  // "true"

delete-ingest-job

fn (job-id: Str): Any
fn (job-id: Str, opts: Map): Any

DELETE /jobs/ingest/{id} - Delete a finished job and its data. Returns null.

Example

::salesforce::bulk/delete-ingest-job("750R0000000000A")

delete-query-job

fn (job-id: Str): Any
fn (job-id: Str, opts: Map): Any

DELETE /jobs/query/{id} - Delete a finished query job and its results. Returns null.

Example

::salesforce::bulk/delete-query-job("750R0000000000A")

failed-results

fn (job-id: Str): Str
fn (job-id: Str, opts: Map): Str

GET /jobs/ingest/{id}/failedResults - CSV of the failed records, with sf__Id and sf__Error columns first.

Example

// Read sf__Error to see why each row failed
::salesforce::bulk/failed-results("750R0000000000A")

get-ingest-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

GET /jobs/ingest/{id} - Job status: state (Open, UploadComplete, InProgress, JobComplete, Failed, Aborted), numberRecordsProcessed, numberRecordsFailed, errorMessage.

Example

job ::salesforce::bulk/get-ingest-job("750R0000000000A")
job.numberRecordsFailed

get-query-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

GET /jobs/query/{id} - Query job status (state, numberRecordsProcessed, ...).

Example

job ::salesforce::bulk/get-query-job("750R0000000000A")
job.state

ingest

fn (object: Str, operation: Str, csv: Str): Map
fn (object: Str, operation: Str, csv: Str, options: Map): Map
fn (object: Str, operation: Str, csv: Str, options: Map, opts: Map): Map

Create an ingest job, upload csv, and close it, returning the closed job (state: "UploadComplete"). Poll it with get-ingest-job / poll-ingest-job. When the upload fails the job is aborted before the Err is returned. See build-ingest-job-body for the options.

Example

rows [{External_Id__c: "u-42", LastName: "Lovelace", Email: "ada@example.com"}]
csv ::salesforce::bulk/to-csv(rows, ["External_Id__c", "LastName", "Email"])
job ::salesforce::bulk/ingest("Contact", "upsert", csv, {external-id-field: "External_Id__c"})
job.id

is-job-finished

fn (job: Map): Bool

True when a job's state is terminal: JobComplete, Failed, or Aborted.

Example

::salesforce::bulk/is-job-finished({state: "JobComplete"})  // true
::salesforce::bulk/is-job-finished({state: "InProgress"})  // false

parse-locator

fn (headers: Any): Any

The Sforce-Locator header as a cursor: null when absent or the literal "null" Salesforce sends on the last page. Exposed for testing.

Example

::salesforce::bulk/parse-locator({Sforce-Locator: "abc"})  // "abc"
::salesforce::bulk/parse-locator({Sforce-Locator: "null"})  // null

poll-ingest-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

Fetch an ingest job and return it once finished, or an Err while it is still running. Run it in a task with a retry policy to wait.

Example

check-job fn (job-id: Str): Map { ::salesforce::bulk/poll-ingest-job(job-id) }

csv ::salesforce::bulk/to-csv([{LastName: "Lovelace"}], ["LastName"])
job ::salesforce::bulk/ingest("Contact", "insert", csv)
::hot::task/start(check-job, job.id, ::hot::task/TaskOptions({retry: {attempts: 20, delay: 5000, backoff: "exponential"}}))

poll-query-job

fn (job-id: Str): Map
fn (job-id: Str, opts: Map): Map

Fetch a query job and return it once finished, or an Err while it is still running (see poll-ingest-job).

Example

// An Err until the job finishes
job ::salesforce::bulk/poll-query-job("750R0000000000A")
if-err(job, (e) { println(`still running: ${e}`) })

query-results

fn (job-id: Str): Map
fn (job-id: Str, options: Map): Map
fn (job-id: Str, options: Map, opts: Map): Map

GET /jobs/query/{id}/results - One chunk of a finished query job's results: {csv, locator, number-of-records}. Pass locator back in options for the next chunk until it is null; max-records caps the chunk size.

Example

job-id "750R0000000000A"
page ::salesforce::bulk/query-results(job-id, {max-records: 50000})
more if(is-null(page.locator), null, ::salesforce::bulk/query-results(job-id, {locator: page.locator}))

results-path

fn (job-id: Str, options: Map): Str

The query-results path with optional locator and max-records parameters. Exposed for testing.

Example

::salesforce::bulk/results-path("750R", {max-records: 100})  // "/jobs/query/750R/results?maxRecords=100"

successful-results

fn (job-id: Str): Str
fn (job-id: Str, opts: Map): Str

GET /jobs/ingest/{id}/successfulResults - CSV of the processed records, with sf__Id and sf__Created columns first.

Example

// CSV text, one row per record
::salesforce::bulk/successful-results("750R0000000000A")

to-csv

fn (records: Vec, columns: Vec): Str

Render records as Bulk-ready CSV (comma-delimited, LF line endings): a header row of columns, then one row per record in that column order. Missing or null values become empty cells, which Bulk treats as "leave unchanged" on update; write #N/A to clear a field.

Example

csv ::salesforce::bulk/to-csv([
  {LastName: "Lovelace", Email: "ada@example.com"},
  {LastName: "Hopper", Email: "grace@example.com"}
], ["LastName", "Email"])

unprocessed-records

fn (job-id: Str): Str
fn (job-id: Str, opts: Map): Str

GET /jobs/ingest/{id}/unprocessedrecords - CSV of the records never processed (e.g. after an abort).

Example

::salesforce::bulk/unprocessed-records("750R0000000000A")

upload-job-data

fn (job-id: Str, csv: Str): Any
fn (job-id: Str, csv: Str, opts: Map): Any

PUT /jobs/ingest/{id}/batches - Upload the job's CSV (header row of field API names first; see to-csv). One upload per job. Returns null on success.

Example

csv ::salesforce::bulk/to-csv([{LastName: "Lovelace"}], ["LastName"])
::salesforce::bulk/upload-job-data("750R0000000000A", csv)