Salesforce Bulk API v2.0 using Mulesoft Connector

When dealing with a single table or object in Salesforce and processing a large volume of data, leveraging the Bulk API v2 is the most suitable approach. This method involves creating a job ID, uploading your data to Salesforce, and letting the Salesforce platform manage the entire process, including job status notifications.

You can find the details of Bulk API jobs and details on Salesforce Developer Guide for Bulk API 2.0. In here, I have tried to summarize Bulk API v2 for you using the flow diagram for a common use case where operations on job can be :

  1. Insert: You can use Bulk API v2 to insert a large number of records efficiently.
  2. Delete: Note that as of now, the “delete” operation is not available in the connector operations yet, but other operations can still be used.
  3. Hard Delete: Bulk API v2 supports the “hardDelete” operation for permanently removing records.
  4. Update: You can perform updates on records using Bulk API v2.
  5. Upsert: The “upsert” operation allows you to insert or update records based on a specifiedexternal ID.

Let’s discuss the some of the operations on the Mulesoft Saleforce connector associated with Bulk API v2.

1. Create job bulk api v2: This connector will pick up the payload in CSV format and upload the job while creating a job ID for ya. Your response will have:

{
    "id": "7508b00000cs0QTAAY",
    "operation": "update",
    "object": "Asset",
    "createdById": "0058b00000G13lcAAB",
    "createdDate": "2023-11-07T05:47:51.000+0000",
    "systemModstamp": "2023-11-07T05:47:51.000+0000",
    "state": "Open",
    "concurrencyMode": "Parallel",
    "contentType": "CSV",
    "apiVersion": 58.0,
    "contentUrl": "services/data/v58.0/jobs/ingest/7508b00000cs0QTAAY/batches",
    "lineEnding": "LF",
    "columnDelimiter": "COMMA"
}

2. Get job state bulk api v2: Use this connector to get the job current state of processing for the job. Values include:

  • Open — The job has been created, and data can be added to the job.
  • UploadComplete — No new data can be added to this job. You can’t edit or save this job, as Salesforce is processing it.
  • Aborted — The job has been aborted. You can abort a job if you created it or if you have the “Manage Data Integrations” permission.
  • JobComplete — The job was processed by Salesforce.
  • Failed — Some records in the job failed. Job data that was successfully processed isn’t rolled back.
{
    "id": "7508b00000cs0QTAAY",
    "operation": "update",
    "object": "Asset",
    "createdById": "0058b00000G13lcAAB",
    "createdDate": "2023-11-07T05:47:51.000+0000",
    "systemModstamp": "2023-11-07T05:48:38.000+0000",
    "state": "JobComplete",
    "concurrencyMode": "Parallel",
    "contentType": "CSV",
    "apiVersion": 58.0,
    "jobType": "V2Ingest",
    "lineEnding": "LF",
    "columnDelimiter": "COMMA",
    "numberRecordsProcessed": 500,
    "numberRecordsFailed": 500,
    "retries": 0,
    "totalProcessingTime": 137,
    "apiActiveProcessingTime": 11,
    "apexProcessingTime": 0
}

3. Retrieve job successful results bulk v 2: Use this connector to get the successful records results. The result will look like

"sf__Id","sf__Created",(CSV payload)

4. Retrieve job failed results bulk v2: Use this connector to get the failed records results. The result will look like

"sf__Id","sf__Error",(CSV payload)

5. Retrieve job unprocessed results bulk v2: Use this connector to get the unprocessed records results. Results are not recorded for batches that exceed the daily batch allocation.The result will look like

(CSV payload that was not processed during the job)- order not maintained

6. Delete job bulk api v2: This connector will ask for JobID. If the current state is UploadComplete, JobComplete, Aborted, or Failed. The job can be deleted.

Return Code 204 for successful job deletion

7. Abort job bulk api v2: Use this if you wish to abort a job while it is in progress. You can abort a job if you created it or if you have the “Manage Data Integrations” permission.

You can also try the operations using the Salesforce Platform API for Bulk API 2.0.  Just fork it onto your user.

Use trailhead exercise Platform API Basics-Bulk API 2.0 to enhance your knowledge on Bulk API v2.0