Salesforce, MuleSoft, and “Hello World!”

Emilio Taylor
6 min readJun 10, 2020

--

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

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.

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
  • On the Trigger page, look for the Salesforce Connector
  • On the Salesforce Connector page, choose On Modified Object
  • 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
  • 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
  • On the Select a component page, search for Set Variable
  • On the Set Variable page, provide the following:
  • Variable Name: salesforce_id
  • Value: Drag & Drop the payload[“Id”]
  • 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
  • On the Select a component page, select Transform
  • On the Transform page, select the [X] to close the component

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
  • On the Select a component page, select the Salesforce Connector
  • On the Salesforce Connector > Select an operation page, select Update
  • On the Salesforce Connector: Update page, provide the following
  • Type = Contact
  • 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
  • On the Transform page, select the Script tab towards the bottom
  • 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

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
  • Select the record to edit
  • Select the edit button. Note the current value in the Description field
  • 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”

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:

--

--

Emilio Taylor

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