Salesforce, MuleSoft, and “Hello World!”

Emilio Taylor
Jun 10 · 6 min read
Image for post
Image for post

Introduction

Whoever said learning a new platform needs to be difficult? Why not start with a simple example and build upon what you’ve learned? The “Hello World” example is ubiquitous for learning any new programming language, so integration platforms like MuleSoft should be no different, right?

In this lesson, our challenge will be to:

  • Create a Contact in Salesforce
  • Have the Contact tracked within MuleSoft
  • Modify the Description field on the Contact to say “Hello World”
  • Send the Contact back to Salesforce to be Updated

Prerequisites

Architecture

Image for post
Image for post

Salesforce: Obtain the Salesforce Security Token

In order to login to Salesforce while using MuleSoft, we need three (3) components:

  • Username
  • Password
  • Security Token

If you don’t already have a Security Token, in this lesson we will reset this token so it’s available to use when connecting to Salesforce while using MuleSoft

Steps:

  • Log in to Salesforce
  • Select the My Account icon and Select Settings
  • On the My Personal Information Page, from the left-hand menu, select Reset My Security Token
  • Check your email for the updated Security Token

MuleSoft: Creating an Application

This is the first step to creating a new application in MuleSoft.

Steps:

  • Go to the Anypoint Platform
  • On the Anypoint Platform homepage, select Start designing under the Design Center section
  • On the Projects page, select the Create New button in the upper-right hand corner
  • On the next menu in order to create an integration using a drag& drop interface, choose the Create new application button
  • On the New Mule Application screen, provide a Project name.
  • Example: GeneralSalesforceUpdate, then click the Create button
  • On the Let’s get started page, select Go straight to canvas.
Image for post
Image for post

Note: This will allow us to choose the trigger and output we need and not include anything unnecessary.

MuleSoft: Select Salesforce Connector: On New Object component

This step will create a connector to Salesforce. We’ll also specify which Object will be monitored for changes

Steps:

  • On the New Flow page, select the Trigger None Selected component
Image for post
Image for post
  • On the Trigger page, look for the Salesforce Connector
Image for post
Image for post
  • On the Salesforce Connector page, choose On Modified Object
Image for post
Image for post
  • On the Salesforce Configuration Page, select Add Connection
  • On the Configure Connection page, provide the following
  • On the Salesforce Connector: On Modified Object page, provide the following:
  • Object Type = Contact
Image for post
Image for post
  • Once done, select the [X] to close the Salesforce Connector

MuleSoft: Select the Set Variable for Salesforce ID component

This step might not always be necessary, but since we want to update the original Salesforce ID further down the process, we want to make sure we hold a copy in the Flow in order to do so. We also perform this step just in case we have any other processes which have an ID value that could potentially overwrite the Salesforce ID we’ve retrieved.

Steps:

  • Select the [+] next to the Salesforce Connector
Image for post
Image for post
  • On the Select a component page, search for Set Variable
Image for post
Image for post
  • On the Set Variable page, provide the following:
  • Variable Name: salesforce_id
  • Value: Drag & Drop the payload[“Id”]
Image for post
Image for post
  • Once done, click the [X] to close the Set Variable component

Note: If you don’t initially see the Payload section, start typing payload[“Id”] into the Value section. MuleSoft will start to populate the payload of the Salesforce record on the right-hand side.

MuleSoft: Select the Transform (DataWeave) component

This is the component where we tell MuleSoft that we’d like to change the data currently flowing in the process. The first time we set up the Transform, we’ll add to the flow, and return on a second pass to complete the mapping.

Note: We do this so the Transform can get connected to the potential destination so it knows what the expected output should look like. This should make the mapping process easier on future steps.

Steps:

  • Select the [+] next to the Set Variable component
Image for post
Image for post
  • On the Select a component page, select Transform
Image for post
Image for post
  • On the Transform page, select the [X] to close the component
Image for post
Image for post

MuleSoft: Select the Salesforce Connector: Update component

This is the step where we define which object will be updated in this MuleSoft application. We’ll connect to the Salesforce Contact object and perform an Update

Steps:

  • Select the [+] next to the Transform component
Image for post
Image for post
  • On the Select a component page, select the Salesforce Connector
Image for post
Image for post
  • On the Salesforce Connector > Select an operation page, select Update
Image for post
Image for post
  • On the Salesforce Connector: Update page, provide the following
  • Type = Contact
Image for post
Image for post
  • On the Salesforce Connector: Update page, select the [X] to close this component

MuleSoft: Update the Transform (DataWeave)

We will now return to the Transform mapping to map the values we’d like to update. This is also the step where other values may be mapped for update

Steps:

  • Select the Transform component
Image for post
Image for post
  • On the Transform page, select the Script tab towards the bottom
Image for post
Image for post
  • On the script tab, copy & paste the following script
%dw 2.0output application/java---[  {     Id: vars["salesforce_id"],     Description: "Hello World"  }]
  • On the Transform page, select the [X] to close the component

MuleSoft: The Completed Flow

Image for post
Image for post

MuleSoft: Test your application

Now that everything is connected, we’ll need to test the process. We’ll log in to Salesforce, open a Contact record, edit the record and watch that the Description is updated to Hello World.

Steps:

  • While in MuleSoft, select the Test button in the upper-right corner
Image for post
Image for post
Image for post
Image for post
  • Select the record to edit
  • Select the edit button. Note the current value in the Description field
Image for post
Image for post
  • While the Test is running in MuleSoft, edit the Phone number on the Contact record.
  • Refresh the Contact and notice that the Description now says “Hello World”
Image for post
Image for post

What’s Next?

That’s It! Wasn’t that easy? With your newfound power, comes great responsibility. Ready to learn more, here’s what I recommend:

Image for post
Image for post

The Innovation

A place for variety of stories from different backgrounds

Sign up for The Innovation Digest

By The Innovation

Official newsletter of The Innovation Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Emilio Taylor

Written by

Salesforce Practice Leader, Technology Enthusiast, Entrepreneur, Integrator, Architect, Developer, and Overall Cloud Advocate.

The Innovation

A place for a variety of stories from different backgrounds

Emilio Taylor

Written by

Salesforce Practice Leader, Technology Enthusiast, Entrepreneur, Integrator, Architect, Developer, and Overall Cloud Advocate.

The Innovation

A place for a variety of stories from different backgrounds

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store