Cyberithub

MuleSoft Integration with Salesforce [Explained with examples]

Advertisements

In this article, we will see how to Integrate Mulesoft with Salesforce using mule salesforce connector. Mulesoft plays a pivotal role in unleashing the power of salesforce by facilitating the integration of Salesforce CRM and Cloud instances to each other or to other enterprise systems, such as ERP or SaaS. It helps customer solving their business needs by unlocking, unifying, and securing data from any system. It provides better experience to customers as they need to deal with less amount of code which in turn saves lot of time. Similarly, Mulesoft provides so many other features that makes it an ideal solution for Salesforce customers.

 

Prerequisites

  • You should have a valid Anypoint platform account
  • You should have a Salesforce developers account
  • You must have some basic knowledge in mule Anypoint Studio
  • Your system should have latest Anypoint studio installed
  • You should have an email id registered to copy security token for authentication.

 

MuleSoft Integration with Salesforce [Explained with examples]

MuleSoft Integration with Salesforce [Explained with examples]

Also Read: MuleSoft Integration with Database [Explained with examples]

Let’s start Mulesoft integration with Mule Salesforce Connector. Before starting our integration, you need to first login to salesforce developer’s account. Then after successful login, go to Profile -> settings -> Reset security token. Follow the number notations one by one. After that, you will get an email to the registered email ID from salesforce to reset your security token.

MuleSoft Integration with Salesforce [Explained with examples] 2

As you can see below, you will get the salesforce username and security token which should be enough to do the basic authentication.

MuleSoft Integration with Salesforce [Explained with examples] 3

Step 1: Create New Project

After successful authentication, first you need to create a new project with some meaningful name like “mule-integration-with-salesforce”. For that you need to go to File ->New -> New Project in Anypoint Studio and name the project “mule-integration-with-salesforce” and then click on Finish.

MuleSoft Integration with Salesforce [Explained with examples] 4

You can see that the project is created with the name of “mule-integration-with-salesforce” as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 5

 

Step 2: Integrate Mule Connectors

Next step is to drag and drop the mule connectors from Mule palette. For example, to use Http listener connector you need drag and drop Http listener in canvas and configure with basic details of host, port and path as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 6

After source in process section, drag and drop required basic connectors to integrate with salesforce like Create connector as shown in below figure.

MuleSoft Integration with Salesforce [Explained with examples] 7

 

Step 3: Configure the Salesforce "Create" connector

In the next step, go to Connection settings and click the plus(+) button. Then choose the connection configuration type as Basic Authentication and then provide below connection details:-

Username: <salesforce_account_username>
Password: <salesforce_account_password>
Security token: <security_token_received_in_email>
Authentication Url :  https://login.salesforce.com/services/Soap/u/55.0

After providing the details, click on Test connection. If all the given details are correct then it will show the result as successful or else it will fail with some missing or incorrect information given error.

MuleSoft Integration with Salesforce [Explained with examples] 8

After successful test connection, click OK to complete the connection configuration of salesforce.

MuleSoft Integration with Salesforce [Explained with examples] 9

 

Step 4: Add Metadata

Next step is to define the input metadata in Http listener. So to add metadata you need to select the Listener and then go to left side panel. There you need to choose metadata -> add metadata ->  choose output payload -> edit it (pencil mark) as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 10

On the select metadata type window, you need to click on Add and then provide the Type id. You can provide some meaningful name like Account as we have given below and then click on Create type.

MuleSoft Integration with Salesforce [Explained with examples] 11

Then select JSON from the drop down list in the Type. After that select Example from the drop down list and browse to the input.json file location which we have defined as mentioned below.

{
  "Name": "Dharma",
  "Active__c": "active",
  "Industry": "software",
  "Phone": "9000000090",
  "site": "anypointplatform.com"
}

MuleSoft Integration with Salesforce [Explained with examples] 12

 

Step 5: Select the type of object

In the next step, you need to go to salesforce Create connector properties General section and select the type of salesforce object as Account(click the refresh button and select the type in case it is not visible).

MuleSoft Integration with Salesforce [Explained with examples] 13

 

Step 6: Transform Message

Now input data map with salesforce account object records in transform message. Transform Message properties in left side input metadata we provided through input.json file and then in the right side salesforce account object data field map input to output by doing just the drag and drop of the field as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 14

 

Step 7: Check Account Object Status

Before we run the POST request to update the Accounts record, you can check the salesforce account object in New this week. You will notice that it is blank and there are no records created here as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 15

 

Step 8: Setup postman request 

Now it is the time to setup postman request and send it to http://localhost:8081/sf/create API to create the record. We will be using POST method with below request body as an example :-

{
  "Name": "Dharma",
  "Active__c": "active",
  "Industry": "software",
  "Phone": "9000000090",
  "site": "anypointplatform.com"
}

MuleSoft Integration with Salesforce [Explained with examples] 16

 

Step 9: Postman response 

After sending the request you should see http response code as 200 which means the request was successfully completed.

MuleSoft Integration with Salesforce [Explained with examples] 17

 

Step10: Verify Account Object

After hitting http request through postman, the record will be inserted successfully in salesforce account object and the same we can verify from below.

MuleSoft Integration with Salesforce [Explained with examples] 18

 

Mulesoft Integration with Salesforce "Update" Connector

Mule connector used to integrate or connect with any system without using bulk code in this way mule salesforce update connector connect with salesforce with a update function. In Anypoint Studio, create a mule flow using salesforce update connector and corresponding mule connectors shown in below figure.

MuleSoft Integration with Salesforce [Explained with examples] 19

To Configure Salesforce update connector, you need to follow below steps:-

Step 1: Update Connector

Salesforce update connector is the function to update salesforce record based on record id. Each record has a specific unique id. Just like before, here also we will configure Connector by selecting Salesforce Global configuration and Type of salesforce object as Account as we have done previously and then save it. It should look like below:-

MuleSoft Integration with Salesforce [Explained with examples] 20

 

Step 2: Update Request

Now update the request with respected Salesforce Record Id. Here we are updating three columns - one is Industry which is updated from software to IT, second is the Phone number and finally the site URL as shown below.

Old data Updated request
{

"Name": "Dharma",

"Active__c": "active",

"Industry": "software",

"Phone": "9000000090",

"site": "anypointplatform.com"

}

 

{

"Name": "Dharma",

"Active__c": "active",

"Industry": "IT",

"Phone": "8888888888",

"site": "anypointplatform.com/mule"

}

 

 

Step 3: Deploy Mule Application

Next step is to deploy the mule application in local machine and send the updated request through postman as shown below. This time the request is sent to http://localhost:8081/sf/update API.

MuleSoft Integration with Salesforce [Explained with examples] 21

You can see that the postman returned with success response as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 22

 

Step 4: Check Record Status

Now if you check the Salesforce Record status by refreshing the web page then you will notice that the record is successfully updated with the new given details you can see below.

MuleSoft Integration with Salesforce [Explained with examples] 23

With this, Mulesoft integration with Salesforce update Connector is successfully completed.

 

Mulesoft Integration with Salesforce "Query" Connector

In this flow, our objective will be to get all the number of account objects in postman response.

Step 1: Integrate Salesforce Connector

  • Create a new flow with the meaningful name of the Flow,
  • Drag and drop from Http listener to source.
  • Select transform message connector to process section.
  • Then place the Salesforce Query Connector.
  • Finally, place another Transform Message connector.

MuleSoft Integration with Salesforce [Explained with examples] 24

 

Step 2: Configuration of all Connectors

  • Configure the http listener with the basic details like host, port, base path and sub path.
  • Transform Message connector will remain the same, just output media format will be selected as default json media type.
  • Then the Salesforce Query Connector configuration will remain same as we used previously. Additionally we just need to configure a SQL query. For example here we are using SELECT Id, Name, Active, Industry, Site, Phone FROM Account query as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 25

  • Lastly Transform Message Connector in output media type needs to be changed to Json format.

 

Step 3: Deploy the Mule Application and test

You can now run the Mule Application in your Local Machine. Once done, you will see all the configurations deployed in your local machine. After successfully deploying the configuration, you can test it by sending a GET Request as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 26

You will notice that the postman request will be successful and in the response body you will see all the records of Salesforce Account Object as shown below.

MuleSoft Integration with Salesforce [Explained with examples] 27

Leave a Comment