Contact Us 1-800-596-4880

Lab 4: Create Composer Flow to Sync Salesforce with Financial System

Overview:

So far we have covered the new Automation Process, reusing one of the existing activities, and publishing it as an API to be invoked by MuleSoft Composer.

On this Lab we cover the definition of the MuleSoft Composer Integration flow:

module4 lab04 flow

As noted in the Module Overview, we first need to get triggered by a new InvoiceSummary Salesforce object:

module4 lab04 object summary

Step 1: Create a New Composer Flow

  1. Login into MuleSoft Composer and select the button to create a new Flow from Scratch.

    module4 lab04 create flow btn
  2. We have created for you part of the Composer flow that can be imported.

    On the top right, click on the tool icon and click on the Import (Beta) button:

    module4 lab04 import
  3. Load the Learners_Repository/Student Files/Module_4_processes/flow_Module_4 - Sync Salesforce with Financial System.json file

  4. As the imported flow makes use of a Salesforce connection and is not included in the file, you must create now such connection.

    In the dropdown menu, select Add New Salesforce Connection

    module4 lab04 create connection
  5. Set the name to <your initials> - Automation Workshop - Salesforce Org Connection and click Connect

    module4 lab04 cnx name
  6. In the next window, login into the Salesforce Developer ORG with the given credentials.

    module4 lab04 sfdc login
  7. Allow access and provide required permissions.

    module4 lab04 sfdc allow
  8. Finally, click Import Flow to import the given template:

    module4 lab04 import flow btn
  9. Click the pencil icon on top-left to rename the newly imported flow.

    module4 lab04 new empty flow
  10. Change the name flow to from

    imported Module 4 - Sync Salesforce with Financial System

    to

    <your initials> - Sync Salesforce with Financial System

    module4 lab04 flow rename
  11. Click on Save button (located on the top-right)

    module4 lab04 save flow

Step 2: Update the Triggering System Event

  1. The imported flow already provides the trigger step, that is, the event handler that will make the whole Composer flow to run.

    As you can see, this trigger event is monitoring in your configured Salesforce organization for New Records of type Invoice Summary:

    module4 lab04 trigger step
  2. An incoming event may contain as many Salesforce object attributes as needed.

    Click the Select Fields button to check which attributes we have selected and will be part of the event payload:

    module4 lab04 selected fields

    Click Cancel to continue.

  3. As you will be using a shared Salesforce organization, it is important to establish a Trigger Condition so that other’s invoices do not trigger your Composer flow.

    In the Trigger Conditions section, expand the filter dropdown list and select the All conditions must be met (AND) option.

    Set the Field to Purchase Order, the operator to Starts With and the value use the following pattern:

    <your initials>-

    module4 lab04 trigger sfdc 3

    Following the above example, this process will only be triggered when you create a new InvoiceSummary object with a Purchase Order starting with CC- such as CC-1234567

Step 3: Create Variable

  1. Click the plus button to add a new step just after the trigger event:

    module4 lab04 add next step after get con
  2. Select the Variable step type.

    We’re going to create and use a variable that will contain the result of the execution of the Automation Process. With this step we will create such variable:

    module4 lab04 create variable step
  3. Select the Create Variable option and click the Add Variable button:

    module4 lab04 variable action
  4. Set the variable Label to Automation Process execution result and Data Type to String and click Apply

Step 4: Add and setup the Error Handler

All needed data is already part of the incoming event payload, so we’re ready to trigger our Automation Process.

module4 lab04 flow2

However, we need to know whether the invokation of the Automation Process went well with no errors and, if so, update Salesforce accordingly.

Thus, we want to handle any error during the execution of the Automation Process

  1. Click the plus button to add a new step just after the Create Variable step and select the Error Handler one:

    module4 lab04 add error handler step
  2. In the On Error section click its own plus button to add our error handler logic:

    module4 lab04 add error handler logic
  3. Select the Variable step, set the action to Update Variable and select the previously created Automation Process execution result one:

    module4 lab04 update variable step
  4. Click on the variable input box and select Custom Expression:

    module4 lab04 variable custom expression
  5. We want to concatenate some strings, including the error type and description.

    Enter the following text in the formula input textbox:

    Error executing the automation process:

    Then, selecting the Data tab on the left handside, locate the Error Handler section and click on the Error Type entry, type : and click again on the Error Description entry. Click Apply to save:

    module4 lab04 build error message

Step 5: Invoke RPA Process

  1. We have added the Error Handler however we haven’t yet set to which actions this error handler is monitoring.

    Still inside the Error Handler step, click the plus button under the Watch section:

    module4 lab04 add watch
  2. Add a new System Action step of type MuleSoft RPA:

    module4 lab04 add rpa step
  3. Configure the MuleSoft RPA Connection as follows

    Field Value

    Connection Display Name

    <your initials> - Automation Workshop - MuleSoft RPA

    Authorization Type

    OAuth 2.0 Client Credentials

    RPA API URL

    https:// + <your tenant hostname> + /rpa/api/v2

    Client ID

    <client id> (provided by the instructor)

    Client Secret

    <client secret> (provided by the instructor)

    Token URL

    For US instances: https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token
    For EU instances: https://eu1.anypoint.mulesoft.com/accounts/api/v2/oauth2/token

    Scopes

    RPA Invocable Process

    module4 lab04 rpa conn wiz

    Click on Connect to save and test the connection settings.

  1. Configure the Invoke RPA Process Action as follows, making sure you select YOUR deployed process (pay attention to the process name’s initials), and click the Select Additional Fields button. Make sure you select your RPA Process that you deployed to Production stage in the previous lab:

module4 lab04 rpa invoke 1

+ . Select the following fields and click Apply:

+

InvoiceDate
InvoiceDueDate
InvoiceNumber
InvoicePurchaseOrder
InvoiceTotal

+ image::module4_lab04_rpa_invoke_fields.png[width="700", align="center"]

+ . Map the fields as follows (all from the Invoice Summary event object):

+ image::module4_lab04_rpa_invoke_mapping.png[width="600", align="center"]

+ . Finally, should the execution of the Automation Process ends successfully, we need to update the variable created previously.

+ Just after the MuleSoft RPA step, click the plus button to add a Variable step. . Set the Action to Update Variable, select the Automation Process execution result variable and enter the text Automation process executed successfully by clicking the Custom Expression button:

+ image::module4_lab04_update_variable_to_ok.png[width="700", align="center"]

Step 6: Update Invoice Record in Salesforce

The previous steps, triggers the MuleSoft RPA Automation Process and awaits for the execution to finish.

Now, we want to update the Salesforce related Account object with the result of the Automation Process execution.

  1. Click the plus icon to add a new step immediatly after the Error Handler step.

    module4 lab04 add next step after rpa
  2. Select a System Action of type Salesforce and select your Salesforce connection

  3. Configure the Salesforce Update Record action as follows and click the Select Additional Fields button.

    module4 lab04 sfdc upd inv 1
  4. Select Sync Result and Last Synched Date and click Apply:

    module4 lab04 sfdc upd inv fields
  5. Map the Record ID field to the Triggering Invoice Record ID, the Sync Result to the Automation Process execution result variable and for the Last Synched Date, click on the Custom Expression button, look for the now function and click on it to add it to the function canvas. Click Apply to save and continue:

    module4 lab04 add now function
    module4 lab04 sfdc upd inv mapping
  6. Save the composer flow by clicking the Save button on the top-right corner.

    module4 lab04 save flow

Please proceed to Lab 5 - Test the Composer Flow