Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Call SalesforceBulkAPI Using the Batch Commit in Mule

DZone's Guide to

How to Call SalesforceBulkAPI Using the Batch Commit in Mule

To send bulk data to SalesforcBulkAPI as an input, the Batch Commit scope in a Batch Step can be used. Here's a brief introduction to SalesforceBulkAPI and Batch Commit.

Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

While loading chunks of data from one system to another system, it is always difficult to process each individual record separately. It is always recommended to process the data in batches; most systems also support this. Similarly, Salesforce provides SalesforceBulkAPI. To send bulk data to SalesforcBulkAPI as an input, the Batch Commit scope in a Batch Step can be used. Here is a brief introduction to the SalesforceBulkAPI and Batch Commit.

SalesforceBulkAPI

Salesforce provides SalesforceBulkAPI to handle very large sets of data. It is a REST-based Bulk API used to process large amounts of data. It is optimized for inserting, updating, upserting, and deleting large numbers of records asynchronously by submitting them in batches to Force.com for being processed in the background.

Mule also has the ability to process messages in Batches using Batch Processing. The BatchCommit scope in a Batch Step is used to process subsets of records within a batch for bulk operations to an external source or service.

Use Case

Fetch the Employee records from HR Database and create Contacts for Employees in Salesforce.com. Follow these steps:

1. Create an Application in Mulesoft.

2. Drag and drop the HTTP connector.

3. Create an HTTP connector configuration by clicking on the + icon.

4. Leave all the defaults and click OK. Under BasicSettings, set the Path as /getEmp and AllowedMethods as GET.

Image title

5. Drag and drop the Database Connector.

6. Configure OracleConfiguration, give the database details, and add the dependency JAR file.

Image title

7. Write the select query to fetch employee details from the database.

Image title

8. Drag and drop Batch Scope to the flow and Batch Step into the Batch Scope.

9. Drag and drop BatchCommit into BatchStep, set the Commit Size property of BatchCommit to 100.

This allows Mule to send sets of records of size 100 to the target system.Image title

10. Drag and drop the Salesforce component into the BatchCommit scope.

11. Configure SalesforceConnector configurations and test the connection.

Image title

12. Select CreateBulk as Operation and Object Type as Contact.

Image title

13. BatchCommit writes a transformation message to convert the EmployeeRecord fetched from Database to Salesforce in an acceptable format for the creation of contacts in Salesforce.Image title

14. This completes Batch Configuration! Drag and drop Batch Execute after the Database component and refer to the Batch Module created above.Image title

The whole application should look like this:

Image title

Run the application and invoke the service from Postman or any browser with the configured URI.Image title

After the successful run of the application, log in to SalesForce. Go to Setup and click on Bulk Data Load Jobs. Verify the jobs created.

Image title

Click on the JobId to see the details of a job.Image title

You can view input requests and results by clicking on ViewRequest and ViewResult.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
mulesoft ,integration ,salesforce ,batchcommit

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}