Salesforce, mulesoft, and “hello world! ”

feature-image

Play all audios:

Loading...

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 * Sign up for


Salesforce Developer Edition * Sign up for MuleSoft 30-day Free Trial 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 * Log in to Salesforce * Find the Contact object * 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: * Expand your MuleSoft knowledge with Training * Learn more Salesforce using Trailhead