Mulesoft Tutorial

Create Bulk Job Salesforce Connector – Mule 4


MuleSoft Bulk Create Job Salesforce Connector


We might need to create bulk jobs in salesforce to perform insert, update or delete on huge records, also once the bulk job created in salesforce, the job runs in background.  In this tutorial we will be looking into how we can create job in Salesforce via Mule 4.

In this Salesforce Mule 4 tutorial we will be using below Mule 4 Salesforce connector to create Bulk V1 job in Salesforce:

  • Create Job
  • Create Batch
  • Close Job

We will be creating Bulk V1 Job with Upsert operation, in salesforce on Account Object. We will be sending Account details as JSON request to Mule 4 application, the application will then be creating a Bulk V1 job with multiple batches inside it. Once all the data is loaded into salesforce Bulk V1 job, mule 4 application will be closing the Bulk V1 job, so no other records or batches can be added to the Bulk V1 job.

We are using mule salesforce connector version 10 in this example.

<dependency>
   <groupId>com.mulesoft.connectors</groupId>
   <artifactId>mule-salesforce-connector</artifactId>
   <version>10.0.0</version>
   <classifier>mule-plugin</classifier>
</dependency>

Create Job

To create Bulk V1 job in salesforce first we need to create a Job. To do so we will be using salesforce “Create job” connector. In “Create job” connector we need to set below parameters.

For Create Job Request, Below are the parameter that we can configure.

In this example we will setting below details in “create job request” transform message before “Create job”.

%dw 2.0
output application/java
---
{
    "externalIdFieldName": "External_ID__c",
    "contentType" : "JSON",
    "concurrencyMode": "Serial"  //Serial or Parallel
}

Note: External_ID__c is a custom field.

On running the Mule Application till here we can create a Bulk v1 job in salesforce but with no Batches inside it. We will get below response once the job at salesforce end is successfully created. This response will contain Job details which is created along with Job ID.

We can also login to salesforce “Bulk Data Load Jobs” and see the job is created there as well.

Once we get the response from create job will save it in a variable for later use. Variable name – “createJobResp”.

Creating Batches

To create a batch inside the salesforce Job, we will be using “Create batch” connector. In this example we are creating multiple batches so running “Create batch” inside for loop.

“Create batch” – Params

Job info should contain details about the job for which we need to create the batch. In this example we are setting “Job info” with the response received on creating the job. That is vars.createJobResp.

Note: To create a batch for the Bulk V1 Job we would need to pass below minimum information in “Job info”, if we donnot have all the information returned from create Job. These details should be same to the Job for which batches are created.

  • id – Job ID
  • contentType – XML, JSON or CSV
  • externalIdFieldName – external field name
  • object – Salesforce object name
%dw 2.0
output application/java
---
{
  id : vars.createJobResp.id,
  contentType: vars.createJobResp.contentType,
  externalIdFieldName: vars.createJobResp.externalIdFieldName,
  object: vars.createJobResp.object
}

Sobjects: Would be the data on which salesforces operations (update/upsert/insert/delete) needs to be performed.

Sample request send for data to be upsert in SObjects  as payload:

Once the batch is created by Mule application at salesforce we will get the Batch details including Batch Id.

We can also login to salesforce “Bulk Data Load Jobs” and see the batch is created there as well.

Closing the Job Created

We would use “Close job” salesforce connector to close the job. All we need to pass here is the Job Id for which we need to close the job.

Note: We can close the job even if batches inside the job are still running, they will continue to run.

Output on Successful execution of Close Job.

 

Download This Project From Here.


About Varun Goel

Varun Goel is a technology enthusiast with 6+ years exp in IT industry. In fact, he is been developing application after schooling as freelancer. Currently working with one of the Fortune’s 100 Companies having vast experience Mule ESB, Tibco, HTML5, CSS, JSS, Android, Core Java, JSP, PHP, MySQL, AutoCAD, Maya, ZBrush, Photoshop, Flash CS and many more.

7 comments

Leave a Reply

Your email address will not be published.