Skip to main content
Join Trailblazers for Dreamforce 2024 in San Francisco or on Salesforce+ from September 17-19. Register now

Design a Flow

Learning Objectives

After completing this unit, you’ll be able to:

  • Prepare to design a flow.
  • Design a flow to automatically sync handwritten leads in Gmail with leads in Salesforce and notifications in Slack.

Prepare to Design a Flow

Recall from MuleSoft Composer Basics that a flow is a sequence of steps you assemble and configure to integrate systems and data. Before designing a flow, you should sketch out the steps of the flow using a flowchart. You can do this using paper and pencil to get a good idea of what your flow will look like.

Here’s an example flowchart showing all the steps of an integration flow for the NTO use case described in the previous unit.

Flowchart for the integration flow for NTO use case.

Here’s a detailed description of the tasks and their associated flow components to create a flow for this NTO use case.

Task

Flow Components

Find any new email with meetup in the subject and an attachment.

Trigger from the Gmail account on new email with the filter meetup has:attachment.

Invoke the Marketing Leads Extractor RPA process.

Action step to invoke the Marketing Leads Extractor RPA process to extract leads from the attachment.

Iterate over the list of extracted leads.

For Each block to iterate over the list of leads returned from the RPA process.

Fetch a corresponding lead, if any, from Sales Cloud.

Action step to get all leads in Sales Cloud that have the same first name, last name, and email as the extracted lead.

Determine if a corresponding lead exists in Sales Cloud.

If/Else block within For Each block to check if the list of leads is empty and the extracted lead’s last name and company aren’t empty.

Note: Last Name and Company are required fields of the Lead object in Sales Cloud.

If a corresponding lead doesn’t exist:

  • Create a lead.
  • Post a message to Slack channel.

In the If branch of the If/Else block:

  • Action step to create a corresponding lead with relevant details in Sales Cloud.
  • Action step to post a message with relevant lead details to the sales-leads Slack channel.

By default, MuleSoft Composer validates your work and provides contextual in-app help every step of the way. For example, when you add a connection to a system, MuleSoft Composer tests the connection to make sure it works before you can proceed to the next step. Also, to simplify building your flows, MuleSoft Composer prompts you to complete required fields within each step.

As a best practice, when building a flow, add a few steps and test iteratively until you complete the flow.

Note

If you have a large integration task, it’s recommended that you break up the task into manageable, bite-sized chunks, and then create a flow for each chunk. This enables you to more easily and quickly build, test, and run your flows to accomplish the task.

Take a look at this video demonstration showing how to sync handwritten leads in Gmail with leads in Salesforce and notifications in Slack using MuleSoft Composer and MuleSoft RPA.

Design a Flow

Now you’re ready to design an integration flow that uses the Marketing Leads Extractor MuleSoft RPA process to automatically sync handwritten leads in Gmail with leads in Sales Cloud and notifications in Slack. 

Follow these steps to design a flow.

Launch MuleSoft Composer from the NTO org.

  1. Log in to your NTO org using your username and password.
  2. From the App Launcher, enter Composer and select MuleSoft Composer.

Create a new flow.

  1. Click Create New Flow.
  2. Click the pencil icon next to the default flow name.
  3. Name the flow Sync Leads using MuleSoft RPA - Gmail to Salesforce to Slack and click Save.

Create the trigger for the flow using an NTO Gmail connection.

  1. Click System Event, and then click Gmail.
  2. Click Add new Gmail connection.
    Note: If this is your first Gmail connection, this option doesn’t appear. Go to the next step.
  3. Name the connection NTO Gmail and click Create.
  4. Click Sign in with Google.
  5. Select the Gmail account that marketing leads are sent.
  6. Select the permissions for MuleSoft Composer to view your email messages, search your email messages, view your settings, and send email on your behalf.
  7. Click Continue to grant MuleSoft Composer the permissions into your Gmail account. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the first step (trigger) of the flow appears.

Configure the trigger to start the flow every time a new email with meetup in the subject and an attachment is sent to a designated Gmail account.

  1. Click in the Choose an event that starts this flow field and select On New Email.
  2. In the Filter Criteria field, enter meetup has:attachment. This enables only emails with meetup in the subject and an attachment to start the flow.
  3. Click Save to save the flow.

Create the second step for the flow using an NTO RPA connection.

  1. Click the plus icon to add a step.
  2. Click System Action, click MuleSoft RPA, and then click Add new MuleSoft RPA connection.
    Note: If this is your first MuleSoft RPA connection, this option doesn’t appear. Go to the next step.
  3. Name the connection NTO RPA.
  4. In the RPA API URL field, copy and paste the RPA API URL from the text file obtained in unit 1.
  5. In the User API Key field, copy and paste the user API key from the same text file.
  6. Click Create. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the second step of the flow appears.

Configure the second step to invoke the Marketing Leads Extractor RPA process with the email subject as the input and the response from the RPA process as the output to be used in this flow. 

  1. Click in the Action field and select Invoke RPA Process.
  2. In the RPA Process field, select Marketing Leads Extractor.
  3. In the Output field, select Use response in this flow.
  4. Click Select Optional Fields, select EmailSubject, and then click Apply.
  5. In the EmailSubject field, select Subject from step 1 of the flow.

Create and configure a For Each block to iterate over each item in the list of leads returned by the Marketing Leads Extractor in step 2 of the flow.

  1. Click the plus icon to add a step.
  2. Scroll down and select For Each.
  3. In the Input list field, select Result > Marketing Leads from step 2 of the flow.

Create the third step for the flow using an NTO sandbox org connection.

  1. Click the plus icon to add a step within the For Each block.
  2. Click System Action, click Salesforce, and then click Add new Salesforce connection.
    Note: If this is your first Salesforce connection, this option doesn’t appear. Go to the next step.
  3. Name the connection NTO sandbox org.
    Note: Even though you’re logged in to your NTO org, you still need to create a connection to it to perform integration tasks.
  4. Select the checkbox This is a sandbox organization and click Create.
    Note: If you use a developer org, skip selecting this checkbox and click Create.
  5. Enter your NTO sandbox org’s username and password and click Log In to Sandbox.
  6. Click Allow to grant MuleSoft Composer the permissions to access the identity URL service, manage user data via APIs, and perform requests at any time. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the third step of the flow appears.

Configure the third step to get all NTO org leads that match the first name, last name, and email of each extracted lead.

  1. Click in the Action field and select Get records.
  2. In the Object Type field, enter Lead.
  3. In the Conditions to filter the objects picklist, select All conditions must be met (AND).
  4. Select First Name as the field, Equals as the operator, and Result > Marketing Leads > First Name from step 2 of the flow.
  5. Click Add a condition.
  6. Select Last Name as the field, Equals as the operator, and Result > Marketing Leads > Last Name from step 2 of the flow.
  7. Click Add a condition.
  8. Select Email as the field, Equals as the operator, and Result > Marketing Leads > E Mail from step 2 of the flow.

Create and configure an If/Else block to check if the list of leads is empty and the extracted lead’s last name and company aren’t empty. 

  1. Click the plus icon to add a step.
  2. Scroll down and click If/Else Block. The All conditions must be met (AND) condition is selected by default.
  3. Select List of Lead from step 3 of the flow as the field and Is empty as the operator.
  4. Click Add a condition.
  5. Select Result > Marketing Leads > Last Name from step 2 of the flow as the field and Is not empty as the operator.
  6. Click Add a condition.
  7. Select Result > Marketing Leads > Company from step 2 of the flow as the field and Is not empty as the operator. If all three conditions are met, it means no corresponding lead exists in the NTO org and the extracted lead has both last name and company, which are required of any new lead by Sales Cloud. A new lead is then created in the NTO org in the next step.

Create the fourth step for the flow using the existing NTO sandbox org connection.

  1. Click the plus icon within the If branch of the If/Else block to add a step.
  2. Click System Action, click Salesforce, and then click NTO sandbox org.
    Note: You reuse the existing NTO sandbox org connection.

Configure the fourth step to sync handwritten leads in Gmail with leads in Sales Cloud.

  1. Click in the Action field and select Create new record.
  2. In the Object Type field, enter Lead. The Company and Last Name fields are automatically selected because they’re required fields.
  3. Click Select Optional Fields, select First Name, Email, Phone, and Description, and then click Apply.
  4. Map the Lead fields to their corresponding fields in the output returned by the Marketing Leads Extractor in step 2 of the flow as follows.
    • Company = Result > Marketing Leads > Company
    • Last Name = Result > Marketing Leads > Last Name
    • Email = Result > Marketing Leads > E Mail
    • First Name = Result > Marketing Leads > First Name
    • Phone = Result > Marketing Leads > Phone
  5. Click in the Description field, and then click Custom Expression. The Custom Expression Editor appears. You use this Custom Expression Editor to configure a message that has both dynamic field values from the preceding steps of a flow (also known as data pills) and static text that you enter.
  6. Configure the following message. Use the Data tab to select the relevant data pills.
    This lead was generated from an email attachment sent to To from step 1 by From from step 1 with the subject line Subject from step 1
  7. Click Apply.

Create the fifth step to sync handwritten Gmail leads with Slack notifications.

  1. Click the plus icon within the If block to add a step.
  2. Click System Action, click Slack, and then click Add new Slack connection.
    Note: If this is your first Slack connection, this option doesn’t appear. Go to the next step.
  3. Name the connection NTO Slack and click Create.
  4. Select NTO from the Slack workspace picklist.
  5. Click Allow to grant MuleSoft Composer the permissions to view content and info about channels and conversations, view content and info about your workspace, and perform actions in channels and conversations in the NTO workspace. The MuleSoft Platform app is automatically added to the NTO Slack workspace, and the fifth step of the flow appears.

Configure the fifth step to notify the sales-leads channel of new leads.

  1. Click in the Action field and select Post message to channel.
  2. In the Channel Name field, click the search picklist, select Pick from List, and then select sales-leads.
  3. Click in the Message field, and then click Custom Expression. The Custom Expression Editor appears.
  4. In the Message field, enter *New lead:*. This uses Slack’s support for the Markdown syntax to turn *New lead:* into New lead: in Slack.
  5. Insert a space, enter Name: , and select Result > Marketing Leads > First Name from step 2.
  6. Insert another space and select Result > Marketing Leads > Last Name from step 2.
  7. Enter , Email: , and select Result > Marketing Leads > E Mail from step 2.
  8. Enter , Phone: , and select Result > Marketing Leads > Phone from step 2.
  9. Enter , Company: , and select Result > Marketing Leads > Company from step 2.
  10. Click Apply.
  11. Leave the Bot Name and Bot Icon URL blank. By default, MuleSoft Composer uses the MuleSoft Platform Slack app to communicate with Slack.
  12. Save the flow. Your entire flow should look like this.
    Step 1 of flow showing a new email with filter criteria meetup has:attachment in Gmail as the trigger.Step 2 of flow to invoke Marketing Leads Extractor RPA process with Subject field from step 1 of flow as input and response from RPA process as output to be used in this flow.For Each block to iterate over list of leads and Step 3 of flow to get all leads with specified conditions.Rest of step 3 of flow with conditions that all leads in NTO org must match the first name, last name, and email of the extracted lead from step 2 of flow.If/Else block with If branch to check if the list of leads from step 3 of flow is empty and the extracted lead’s last name and company from step 2 of flow aren’t empty.Step 4 of flow within If branch to create a lead in the NTO org using the last name and company from the extracted lead in step 2 of flow and the description from the To, From, and Subject fields in step 1 of flow.Rest of step 4 of flow within If branch to create a lead in the NTO org using the email, first name, and phone from the extracted lead in step 2 of flow.Step 5 of flow within If branch posting message containing first name, last name, email, phone, and company from the extracted lead in step 2 of flow to sales-leads Slack channel.

Good job! In the next unit, you learn how to test your flow to ensure it works as expected.