Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Make Decisions and Perform Repetitive Actions

Learning Objectives

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

  • Make decisions using an If/Else Block.
  • Perform repetitive actions using a For Each loop.

Make Decisions Using an If/Else Block

So far, you’ve learned to create a flow that proceeds from one step to another. With MuleSoft Composer, you can also make decisions about what actions your flow must perform if the input data from a previous step of the flow satisfies one or more specified conditions. 

To do this, add an If/Else Block along with associated actions to your flow. 

  • In the If branch of the flow, evaluate the input data based on a condition.
  • If the condition is met, perform the actions in the If branch.
  • If the condition isn't met, perform the actions in the Else branch.

Let’s look at an example use case. Your customer support team at NTO manages and maintains customer service cases in the NTO org’s Service Cloud. For best customer service, the team also collaborates using a Slack channel with other stakeholders such as sales, product, and technical support teams to resolve cases. 

To automate the data sync between Service Cloud and Slack, you need to create a flow that automatically syncs the creation or update of customer service cases in Service Cloud with case notifications in Slack.

First, assume you’ve already created a flow that starts every time a new case is created or updated in Service Cloud. In the trigger, all fields of the Case object are selected by default.

Next, let’s add a decision to this flow. In this decision, your flow must evaluate if the status of the case fetched in step 1 of the flow is set to Escalated. 

  • If it is, send a direct message to the support regional leader, @Jane Doe.
  • If it isn’t, send a message to the services-cases channel.

Here’s how to create and configure an If/Else Block and associated action steps for this flow.

  1. Click the plus icon to add a step.
  2. Scroll down and click If/Else Block. In the If branch, the All conditions must be met (AND) condition is selected by default.
  3. Click in the Field name and select Status, click Operator and select Equals, and then enter Escalated in the Value field.
    If/Else block with condition of status equaling escalated.
  4. Click the plus icon to add a step to the If branch.
  5. Click Slack.
  6. Create and configure a connection to Slack. Upon a successful connection, step 2 of the flow appears.
  7. Click in the Action field and select Send a direct message to a user.
  8. Click the search icon of the User field, select Pick from List, and select the Slack username of the support regional leader. In this example, it’s @Jane Doe.
  9. Click in the Message field and then click Custom Expression. The Custom Expression Editor appears.
  10. In the Message field, enter Case Number: , click the Data tab, and then select Case Number from step 1 of the flow.
  11. Repeat step 10 for Case Reason and Status. Your message looks like this.
    Case Number: Case Number from step 1, Reason: Case Reason from step 1, Status: Status from step 1
  12. Leave the Bot Name and Bot Icon URL blank. By default, MuleSoft Composer uses the MuleSoft Platform Slack app to communicate with Slack.
    Step 2 of flow to send a direct message to a Slack user.
  13. Click Add Else.
  14. Click the plus icon to add a step to the Else branch.
  15. Click Slack and then click the existing Slack connection.
  16. Click in the Action field and select Post message to channel.
  17. In the Channel Name field, click the search picklist, select Pick from List, and then select service-cases.
  18. Click in the Message field and then click Custom Expression. The Custom Expression Editor appears.
  19. Configure the message as follows.
    Case Number: Case Number from step 1, Reason: Case Reason from step 1, Status: Status from step 1
    Else branch with step 3 of flow to post message to Slack service-cases channel.
  20. Save the flow.

Perform Repetitive Actions Using a For Each Loop

With MuleSoft Composer, you can also perform repetitive actions on a list of items coming from a previous step of the flow. To do this, use a For Each loop to iterate over each item and then perform one or more actions for each item. 

Before you can use the For Each loop, ensure a relevant list of items has been fetched from a previous step of the flow, using a Get records action.

Let’s look at an example use case. Your sales team at NTO manages and maintains sales leads in the NTO org’s Sales Cloud. For best leads management, the team needs to identify those leads that have not been contacted by a sales rep in the last 24 hours. 

First, assume you’ve already created a flow that starts once a day using a scheduler. In the first action step, all leads that have the status of not contacted are fetched by using the Get records action on the Lead object in Sales Cloud. Your flow should look like this so far.
Step 1 of flow with scheduler to start flow everyday.Step 2 of flow to get leads with condition of status containing not contacted.

Next, let’s add a repetitive action to this flow using a For Each loop. In this loop, your flow iterates over each lead. Your flow then creates a corresponding row containing email, first name, last name, lead source, and phone in the Marketing Event Tracker spreadsheet in Google Sheets. 

Here’s how to create and configure a For Each loop and an associated action step for this flow.

  1. Click the plus icon and then select For Each.
  2. In the Input list field, select List of Lead from step 2 of the flow.
    For Each block looping over list of leads from step 2 of flow.
  3. Click the plus icon to add a step to the For Each loop.
  4. Click Google Sheets.
  5. Create and configure a connection to Google Sheets.
  6. Click in the Action field and select Create row.
  7. Click in the Spreadsheet ID field and select Marketing Event Tracker.
  8. Click in the Worksheet name field and select Sheet1.
  9. Click Add Columns, select all fields, and click Add.
  10. Map the Lead fields from step 2 of the flow to their corresponding fields in the Marketing Event Tracker spreadsheet as follows.
    • Email = Email from step 2
    • First Name = First Name from step 2
    • Last Name = Last Name from step 2
    • Lead Source = Lead Source from step 2
    • Phone = Phone from step 2Step 3 of flow to create row in Marketing Event Tracker spreadsheet with values such as email, first name, and last name.

Nice job! You’ve learned how to make decisions and perform repetitive actions in your flow. In the next unit, you learn how to transform data using functions and formulas.

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback