MuleSoft-Salesforce Integration using Bulk API V2 Connector

Author: Rahul Dusaje

We will look at two operations:  Upsertion, for creating/ updating the records from a File to Salesforce and DELETE operation to soft delete records from Salesforce.

UPSERT Operation: 

This operation allows us to create/ update an existing record in salesforce, provided the record Id/ external ID it uses as a key to match records.

DELETE operation: 

Records deletion in salesforce can be either a Soft Delete or Hard Delete.

SOFT DELETE VS HARD DELETE operation:

When the records in Salesforce are Hard Deleted they do not persist in the Recycle Bin, however, the records can be retrieved back again from the recycle bin if deleted through Soft Deletion operation.

In this blog, I will walk you through the upsert and delete operation using the Create Bulk Job API V2 connector.

For this exercise, I created a custom object DemoAccount 

There are three custom fields in this object:
  1. Contact_name__c
  2. Contact_id__c
  3. Contact_email__c 

The Sample Data consists of 1000  records and looks like this.

UPSERT SYNC MULESOFT FLOW:

The Read Component fetches the records from the Sample File and 

Transform Message maps the data fields to salesforce custom object’s fields.

The Create Job Bulk API V2 is configured with Basic Authentication to connect with Salesforce Org. 

The best part about using the Salesforce bulk job APIs is that it can be tracked in Salesforce UI. 

Goto Setup-> Bulk Data Load Job 

It helps us track the Job IDs, Job Status, Records upserted successfully, Records Failed.

Here in our case, 479 records failed out of 1000 because of the duplicate contact_id which is an external key/ Id in salesforce. 

NOTE: Ideally the external Id contains unique values to identify the individual records.

DELETION SYNC MULESOFT FLOW:

For Deleting the records from Salesforce, the salesforce generated record Id needs to be provided. For that, the records are queried from the object and passed as a parameter to Create Job Bulk API v2 connector.

Query Connector:
Mapper:
Create Bulk Job API Connector:

The external ID is set to Id(Salesforce’s record ID) and the operation is set to DELETE

References: 

Salesforce Bulk API V2

UPSERTION in Salesforce

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.