
A straightforward guide to using Salesforce Bulk API 2.0
Bryan Ferreira
UploadCompleteJobCompleteCreate a job specifying the object and operation type.
POST /services/data/v65.0/jobs/ingest
{
"object": "Account",
"operation": "update" // or "insert", "upsert", "delete"
}
Response:
{
"id": "750xx000000XXXXAAA",
"operation": "update",
"object": "Account",
...// We will be just using the id from here
}
Upload your data in batches as CSV.
PUT /services/data/v65.0/jobs/ingest/750xx000000XXXXAAA/batches
Content-Type: text/csv
Id,TextExampleField__c,NumberExampleField__c
001Xx000003XXXXAAA,Sample Text,12345
001Xx000003XXXXAAA,Another Text,67890
Keep in mind:
text/csvSend a request notifying that all the data has been uploaded.
PATCH /services/data/v65.0/jobs/ingest/750xx000000XXXXAAA
{
"state": "UploadComplete"
}
After this request, Salesforce will proceed to process all the uploaded data from the batches.
Send a GET request to check the job status, until the state is JobComplete.
GET /services/data/v65.0/jobs/ingest/750xx000000XXXXAAA
Response:
{
"id": "750xx000000XXXXAAA",
"state": "JobComplete",
"numberRecordsProcessed": 2,
"numberRecordsFailed": 0,
// Other fields that we won't be using
}
If the status is Failed or Aborted, something went wrong. Then you can check the error messages in the KOs section below.
GET /services/data/v65.0/jobs/ingest/750xx000000XXXXAAA/successfulResults/
GET /services/data/v65.0/jobs/ingest/750xx000000XXXXAAA/failedResults/