Add Logic to Your Flow

Learning Objectives

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

  • List the logic elements available in Flow Builder.
  • Add branching logic to a flow.
  • Change a variable value in a flow.

Create Branches with Decision Elements

For most business processes, rules determine whether a particular action should be taken or not. Maybe a case should be escalated when the associated account is at risk. The rule in play here is “the associated account is at risk.” In Flow Builder, you evaluate the rules of your business process by using Decision elements.

Each decision answers a question, and the outcomes provide the possible answers. The answers can be as simple as Yes and No, but there’s no limit to the number of answers. You determine which answer is appropriate by configuring conditions for each outcome. When a flow executes a Decision element, it evaluates each decision outcome in order. If an outcome’s conditions are met, the flow takes the associated connector and ignores the other outcomes. If an outcome’s conditions are not met, it evaluates the next outcome in the list.

Flow Builder provides the last outcome for you, which has no conditions: the default outcome. It acts as a fallback. When the conditions for every other outcome aren’t met, the flow takes the connector for the default outcome.

As an example, let’s look at the decision you built in the New Contact flow. Notice that the Update or Create? decision has two connectors and, unlike the others in the flow, these connectors are labeled: Create New and Update Existing.

The “New Contact” flow, where the “Update or Create?” decision and its outcomes are highlighted.

Double-click the Update or Create? decision to open it.

Details for the “Update Existing” outcome, which evaluates whether the {!update_toggle.value} variable is true and whether the {!Find_a_Match.Id} variable is not null.

Under Outcome Order (1), you see two outcomes whose labels match what you just saw on the canvas. Each decision outcome has an associated connector on the canvas.

In Outcome Details, you see the conditions (2) for the Update Existing outcome.

{!update_toggle.value} equals {!GlobalConstant.True} This condition evaluates whether the user opted to update the existing record. The {!update_toggle.value} represents the value from the Toggle component on the Contact Info screen. If the user activates the toggle, {!update_toggle.value} is set to true and this condition is met.


To validate a Boolean value, such as for a toggle or checkbox, always use the global constants for true or false. If you manually enter true, that’s the equivalent of the word true rather than the Boolean value that you want.

{!Find_a_Match.Id} Is null {!GlobalConstant.False} This condition evaluates whether the flow found a matching record. {!Find_a_Match.Id} is set in when the Find a Match element finds a matching record. If {!Find_a_Match.Id} is not null, this condition is met.

Because When to Execute Outcome is set to All Conditions Are Met, both of these conditions must be true for the flow to take the Update Existing path. Otherwise, the flow evaluates the next outcome in the list.

Under Outcome Order, click the Create New. Notice it has no conditions. That’s because it’s the default outcome, relabeled to better answer the decision’s question (Update or Create?) on the canvas. If the conditions aren’t met for the flow to update the existing record, the flow should always create a new one.

The default outcome, which is labeled “Create New”



We suggest using the default outcome as the last answer to your decision’s question. For example, if the possible outcomes are Yes and No, configure conditions for the Yes outcome, and relabel the default outcome to No. If the answer isn’t Yes, it’s No.

In summary, when the flow executes the Update or Create? element, it evaluates whether the requirements are met for the flow to update the record (the user opted to update the existing record and there’s a matching record to update). If those requirements are met, the flow takes the Update Existing path. Otherwise, it takes the Create New path. Later in the module, you go over the actions the flow executes on these paths.

Update Variable Values with Assignment Elements

Earlier in this module, you learned about the importance of flow variables and how they can change values during the flow. The easiest way to change a variable’s value is with an Assignment element.

Use each row to modify a variable. How the variable value changes depends on the operator selected and the value set. For example, the Add operator works differently for different data types. For Date variables, Value is added in days to the selected Variable’s value. For Text variables, the text entered or selected for Value is added to the end of Variable.

Let’s look at the assignment you built in the New Contact flow.

From the canvas, double-click the Set Contact ID node. The element updates one value: the Id field on the {!contact} record variable.

The “Set Contact ID” assignment, which sets the ID field on the {!contact} variable to the value stored in the {!Find_a_Match.Id} variable.

Why do you need this assignment? Because a flow can’t update a record if it doesn’t know which record to update.


Flow Builder includes two other logic elements not covered in this module: Loop and Pause.

Update the Flow

The way the flow is currently built, it looks for a matching contact record before determining whether to update the existing one or create a new one. That’s a wasted data element: Why look up the ID of a matching record if the user opts to create a new contact anyway?

To fix that, let’s break the existing decision into two decisions. The Update or Create? Decision element checks two conditions: whether the user opted to update the existing record or not, and whether a matching contact record exists.

You move the first condition into its own Decision element, so you only use the Get Records element if the user opted to update a matching record. If the user didn’t, you won’t bother looking for a matching record.

Create a New Decision

  1. Drag a Decision element onto the canvas.
  2. Give the decision a label: Update If Existing? The API Name is automatically set to Update_If_Existing.
  3. Give the first outcome the label Yes. Update the API Name to Update_Yes. This way, the label for the decision connector is easy to read, but you can easily differentiate the name of that outcome from others in the Manager tab.
  4. Leave When to Execute Outcome as is, and configure one condition for the outcome. Note You can’t copy and paste the Resource value. Type update_to into Resource, click on update_toggle >, then select Value.
    Field Value
    Resource {!update_toggle.value}
    Operator Equals
    Value {!$GlobalConstant.True}
  5. Under Outcome Order, click Default Outcome. Change its label to No. If you leave the outcome label as Default Outcome, it might not be obvious when that outcome is executed.
  6. Click Done.

Update the Original Decision

Now that you’ve added the new decision, the original decision (Update or Create?) has a redundant condition. Let’s remove it!

  1. Double-click Update or Create?.
  2. Find the condition that matches what you added to the Update if Existing? decision. The Resource field should contain {!update_toggle.value}.
  3. For that condition, click Delete icon
  4. Click Done.

Reconnect the Elements

You’re almost done! To finish, you need to make sure the Update If Existing? decision is executed before the Find a Match element.

  1. Remove the connector between Contact Info and Find a Match.
    1. Click the connector. When it’s highlighted, the color changes to blue.
    2. Press the Delete key.
  2. Connect Contact Info to Update If Existing?.
  3. Connect Update If Existing? to Find a Match. When prompted, select the Yes outcome, and click Done.
  4. Connect Update If Existing? to Create Contact. Since there’s only one outcome left to connect (No), Flow Builder automatically selects it for you.
  5. Save the flow, and ignore the FYI warning.

The “New Contact” flow, where the new “Update if Existing?” decision and its paths are highlighted.

Now the flow has two decision points. First, it evaluates whether to look for a matching record, based on whether the user opted to always create a new contact or not. Second, it evaluates whether the Find a Match element found a matching contact or not.


Keep learning for
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities