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

MuleSoft, Salesforce POST

DZone's Guide to

MuleSoft, Salesforce POST

Take a look at this tutorial for more information on how to create a simple global HTTP connector to receive requests in Salesforce.

Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

HTTP Config:

MuleSoft has Salesforce connectors that facilitate CRUD operations for Salesforce objects. If you need to get data from Salesforce, take a look at MuleSoft, Salesforce Request.

HTTP Connector:

We are going to create a simple global HTTP connector to receive our requests:

Image title

To make the example simple, we are going to create the following flow:

  •     /contacts POST  

Image title

HTTP config:

Image title

Salesforce Connector:

Drag and drop the Salesforce connector right after the GET HTTP:

Image title

  • Select Salesforce Basic Authentication

  • Fill out the username, password, and security tokens with Salesforce credentials.

  • Click validate configurations to check the connection.

Image title

Salesforce Create:

Going back to the Salesforce connector, select Create as Operation.

We are going to create a Contact so select it as sObject type.

Keep the sObject Field Mappings as default. From Expression #[payload]

Image title

Drag and drop a transformer connector between HTTP and Salesforce. Doing that, you can make use of the data sense to help you to make the transformations.

Image title

Image title

We are going to use the following payload to create a contact:

{
"last_name": "Obama",
"first_name": "Barack",
    "cel": "555 6987",
    "personal_email": "bo@whitehouse.com"
}

The MuleSoft Transformer should look like this:

%dw 1.0
%output application/java
---
[{
LastName: payload.last_name,
FirstName: payload.first_name,
Phone: payload.cel,
Email: payload.personal_email
}]

Image title

NOTE: Pay special attention to %output, as it should be application/java

Add another transformer connector after the Salesforce connector. It will be responsible for transforming the resulted Salesforce message into JSON format.

Image title

The transform message should look like this:

%dw 1.0
%output application/json
---
{
    id: payload[0].id,
    success: payload[0].success
}

Image title

Creating a Contact

Start the Mule project from Postman, make a post request, and pass the contact JSON as a parameter:

{
"last_name": "Obama",
"first_name": "Barak",
    "cel": "555 5555",
    "personal_email": "bo@test.com"
}

Image title

The JSON response should indicate if the contact was properly created.

Opening Salesforce, we can find our created Contact (Barak Obama).

Image title

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:
mulesoft ,salesforce ,integration ,tutorial ,http ,connectors ,crud ,post ,global http connector

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}