Guides / n8n × Salesforce / Reliability

Salesforce Bulk API vs REST: how error handling differs

REST tells you immediately and per request; Bulk 2.0 tells you afterwards, per row, in a results file you have to fetch. The two failure models, and the retry logic each one needs.

Illustrated troubleshooting diagram for Salesforce Bulk API vs REST API: how error handling differs.
A Bulk 2.0 job reaching state JobComplete while numberRecordsFailed is greater than zero — a success status covering rows that were rejected.
Short answer: REST composite and sObject calls fail synchronously: you get a status code and an errorCode per request, and allOrNone decides whether one bad row rolls the batch back. Bulk API 2.0 is asynchronous and partial by design — the job completes, numberRecordsFailed reports how many rows were rejected, and the reasons live in a separate failedResults file you must fetch and parse. A Bulk integration that only checks job state silently discards every rejected row.

Two failure models

With REST, the response is the answer. A single-record create returns 201 or a 400 with an array naming errorCode, message and the offending fields. A composite request returns a per-subrequest result. Either way the outcome is known before the call returns, and error handling is ordinary request handling.

With Bulk 2.0 the submission and the outcome are separate events. You create a job, upload CSV data, close it, and poll until the state becomes JobComplete. That state means processing finished — not that it succeeded. The counts in the job status tell you how many rows were processed and how many failed, and the per-row reasons are only available by fetching the failedResults file.

REST vs Bulk API 2.0 error handling

RESTBulk API 2.0
When you learnIn the responseAfter polling to JobComplete
GranularityPer request (or per subrequest)Per row, in a results file
Partial successControlled by allOrNoneAlways partial — good rows commit
Error detailerrorCode + message + fieldssf__Error column in failedResults CSV
JobComplete meansn/aProcessing finished, not that it worked
Allocation consumedDailyApiRequestsBulk job and batch allocations

The Bulk flow, including the step people skip

The last step is the one that gets omitted. A job reporting JobComplete with numberRecordsFailed of 400 out of 50,000 has committed 49,600 rows and rejected 400, and unless something fetches failedResults those 400 records are simply absent from Salesforce with nothing anywhere recording why.

Fetch both result files. successfulResults carries the created or updated IDs, which is what you need to write back your own mapping; failedResults carries the reason per row in an sf__Error column, and those reasons are the same error codes REST would have returned.

POST /services/data/v66.0/jobs/ingest
{ "object": "Contact", "operation": "upsert",
  "externalIdFieldName": "External_Id__c", "lineEnding": "LF" }
# -> { "id": "750...", "state": "Open" }

PUT   /services/data/v66.0/jobs/ingest/750.../batches     (CSV body)
PATCH /services/data/v66.0/jobs/ingest/750...            { "state": "UploadComplete" }

GET   /services/data/v66.0/jobs/ingest/750...
# -> { "state": "JobComplete",
#      "numberRecordsProcessed": 50000,
#      "numberRecordsFailed": 400 }        <- NOT a failure state

GET /services/data/v66.0/jobs/ingest/750.../failedResults/
# sf__Id,sf__Error,External_Id__c,LastName,Email
# ,REQUIRED_FIELD_MISSING:Required fields are missing: [LastName]:LastName,E-1001,,a@b.com
# ,INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST:bad value for restricted picklist field: gold:Tier__c,E-1002,Lovelace,

GET /services/data/v66.0/jobs/ingest/750.../successfulResults/

allOrNone is the REST decision you must make deliberately

On a REST composite or collections call, allOrNone true means one invalid row rolls the entire batch back — nothing commits. allOrNone false means valid rows commit and invalid ones are reported individually, which is the same partial-success model Bulk uses.

Neither is right in general. A financial posting where a partial write leaves inconsistent state wants all-or-none. A lead import where 199 good records should not be held hostage by one bad email wants partial. What is never right is leaving it at the default without deciding, because the default determines whether a single malformed row costs you 199 successful writes.

With allOrNone false, the response array is positional: the result at index 7 belongs to the input at index 7. Preserve that correspondence when building the retry set, or the retry will resend rows that already committed.

PATCH /services/data/v66.0/composite/sobjects
{
  "allOrNone": false,
  "records": [
    { "attributes": {"type":"Contact"}, "id":"003...", "LastName":"Lovelace" },
    { "attributes": {"type":"Contact"}, "id":"003...", "Tier__c":"gold" }
  ]
}

# -> [ { "id": "003...", "success": true,  "errors": [] },
#      { "id": null, "success": false, "errors": [
#          { "statusCode": "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST",
#            "message": "bad value for restricted picklist field: gold",
#            "fields": ["Tier__c"] } ] } ]
#
# Index 1 failed, index 0 committed. Retrying the whole array
# re-sends a row that already succeeded.

The same error codes, two different retry strategies

The error codes are shared across both APIs, and their retryability is identical. REQUIRED_FIELD_MISSING, INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, DUPLICATE_VALUE and FIELD_CUSTOM_VALIDATION_EXCEPTION are data problems: retrying an unchanged row reproduces them exactly. UNABLE_TO_LOCK_ROW and server errors are transient and worth retrying with backoff.

What differs is the unit of retry. In REST you retry the failed subrequests, identified positionally. In Bulk you build a new CSV from the rows in failedResults whose sf__Error is transient, and submit it as a new job — the original job is immutable once complete.

Make both paths idempotent by using upsert against an external ID field rather than insert. A retry then updates the row it created on the first attempt instead of creating a second one, which is what makes an interrupted 50,000-row job safe to re-run at all.

  • JobComplete is not success — always read numberRecordsFailed.
  • Always fetch failedResults; sf__Error carries the per-row reason.
  • Fetch successfulResults too, to write back the Salesforce IDs.
  • Decide allOrNone deliberately; it is not a detail.
  • Retry only transient codes; dead-letter data errors with their reason.
  • Upsert on an external ID so retries cannot duplicate.

Choosing between them for a given job

The decision is usually made by volume and latency rather than by error handling, but error handling should inform it. REST is right when the caller needs to know the outcome immediately and act on it — a user is waiting, or the next step depends on the created ID. It is also right for small volumes, where the operational overhead of job management buys nothing.

Bulk is right for large volumes, and it brings a genuine advantage beyond throughput: it draws on a different allocation, so a 100,000-record import through Bulk leaves the synchronous request budget intact for everything else in the org. A REST-based import of the same data can exhaust DailyApiRequests and take every other integration down with it.

The cost is that outcomes are asynchronous and partial, so the workflow needs a polling step, a results-fetching step and somewhere to put rejected rows. That is real work, and it is the reason people reach for REST at volumes where Bulk would clearly be better — the simpler error model is worth something right up until the allocation runs out.

A reasonable rule: below a few thousand records, REST with allOrNone set deliberately. Above that, Bulk with the full results-handling path built, including the failedResults fetch.

Where these facts come from