Conditional Visibility in Salesforce Flows

In Salesforce, we create records with the help of forms, and these forms have various fields and components by adding Component Visibility, where we have to state conditions to control, such as whether a specific field is visible or not on a record page.

In Salesforce Screen flows, we can add conditional visibility to any specific field or component. In this Salesforce tutorial, we will learn to use and add Conditional visibility for components in Salesforce Screen flow.

Flow Conditional Visibility Considerations

For setting visibility for a screen component, there are some following considerations.

  • The null value is always evaluated as an empty string.
  • Operators like ‘Was Visited‘ and ‘Was Set‘ aren’t supported in conditional visibility.
  • The Apex-defined data types and Record variables data types aren’t supported in conditional visibility, but you can reference attributes and fields.
  • Any screen input component with Manually assign variables (advanced) selected isn’t available as a resource for conditional visibility on the same flow screen.
  • Text that has merge fields included isn’t supported in values. Merge fields on their own are supported.

Create a Screen flow with Component Visibility in Salesforce

In this example, I will create a Screen flow to explain component visibility. With flow, we will create Account records, and there will be two address fields: Billing Address and Shipping address. We will add a condition: if the Shipping address is the same as the Billing address, then the Shipping address section will not appear on the screen.

To create a Screen flow with Component Visibility in Salesforce, navigate to the setup page and follow the below steps.

See also  How to Create and Deploy Scheduled-Trigger Flow in Salesforce

1. Go to the Quick Find box, and search, then select Flows under Process Automation.

2. In the flows setup, click New Flow. In the next window, select the option Screen flow.

3. Enter the Lable and API Name for the Screen element.

In the screen, we will add fields that will create an Account record and then add component visibility in those fields.

4. Add a Text element to the screen and label it as Account Name. After this, add a Phone element to the screen and enter the Label and API name for that, too.

Conditional visibility in Salesforce screen flow

5. Now, we will add two address components, one for the Billing Address and another one for the Shipping Address. Enter the API Name and Label for both Address components.

Add Conditional visibility for component in Salesforce flow

6. To add the component visibility to the Shipping address component, we will add a Checkbox component to the screen (above the shipping address component).

Conditional visibility in Salesforce flow

7. Select the component on which you want to add conditional visibility and go to the section Set Component Visibility. In the Condition requirements, select the Resource as Checkbox name and Value as false. After this, click Done.

According to this condition, the Shipping address will be visible when the Checkbox is not selected.

At last, click Done to save the Screen.

Use Conditional visibility in Salesforce screen component

8. If the user selects the checkbox, the Shipping Address should be auto-filled, and for that, we will add a Decision element with the details below.

  • Enter the Label and API Name for the Decision element.
  • In the section Outcome Details, enter the Label and Outcome API Name.
  • In the Condition Requirements, select the Resource as Checkbox and Value as True.
How to configure conditional visibility in Salesforce screen flows

9. Now, we will create a resource that we will use in the Assignment.

See also  How to Delete Related Records Using Flow Action in Salesforce

Create a New Resource with the following details.

  • Select the Resource Type as a Variable.
  • Write APIName as accountRecord.
  • Select Data type as Record.
  • Select the Object as Account and click Done.
How to use conditional visibility in Salesforce flow

10. Now add an Assignment element to the flow. After this, enter Name and API Name. This assignment element will map the Address fields with their values in flow.

Now map the following Fields with respective values for the Billing Address. In the below mapping, accountRecord is the Record type variable that we created.

VariableValues
accountRecord > Account NameAccount_Name
accountRecord> Billing CityBilling _address > City Value
accountRecord> Billing StreetBilling _address > Street Value
accountRecord> Billing Postal Billing_address > Postal Code Value
accountRecord> Billing StateBilling_address > State Value
accountRecord> Billing CountryBilling Address > Country Value
Make component visible in Salesforce flow with conditional visibility

11. Map the below fields to fill details of the shipping address from the billing address.

Variable Value
accountRecord > Shipping CityBilling_address > City Value
accountRecord > Shipping StreetBilling_address > Street Value
accountRecord > Shipping Zip/PostalBilling_address > Zip/Postal Value
accountRecord > Shipping CountryBilling_address > Country Value
accountRecord > Shipping StateBilling_address > State Value
How to add conditional visibility to component in Salesforce flow

12. Now, we will configure the decision element’s default outcome when both addresses are different. In the default outcome, copy-paste the Assignment element of the same address.

Conditional visibility on Component in Salesforce Screen flow

13. Edit the Assignment element of the Default Outcome and change the Label. After this, update the values for the Shipping address variables.

Variable Value
accountRecord > Shipping CityShipping_address > City Value
accountRecord > Shipping StreetShipping_address > Street Value
accountRecord > Shipping Zip/PostalShipping_address > Zip/Postal Value
accountRecord > Shipping CountryShipping_address > Country Value
accountRecord > Shipping StateShipping_address > State Value
Add Conditional visibility for component in Salesforce Screen flow

14. Add a Create Record element and enter Label to create a record element. In the Record field, select the Resource Variable that we have created.

Add Conditional visibility in Salesforce Screen flow component

15. Copy the Create Record element and paste it below the Default Outcome’s Assignment element.

See also  How to Automate Assets Creation using Flows in Salesforce

16. The flow is completed, Now save it with relevant flow label.

Debug the created Screen Flow

Follow the below steps to check the component visibility in the flow.

1. Click on the Debug button in the flow builder.

Conditional visibility in Salesforce screen flow component

2. In the Debug Flow window, click on the Run button.

3. Fill in the details of the Billing address and click on the checkbox Shipping Address same as the Billing Address. As we click on the checkbox, the Shipping Address component will disappear from the screen.

Create a Screen flow with conditional visibility

4. At last, click Next to create a record.

Now, in the results, we can see that the Shipping address is filled from the values of the Billing address.

Use Conditional visibility in Salesforce screen flow components

In this way, we can add conditional visibility in Salesforce screen flows by following the above steps.

Conclusion

In Salesforce Screen flows, we can make screen forms more dynamic by adding conditional visibility to the components. In this Salesforce tutorial, we learned the method of adding conditional visibility to the Screen flow component with the help of the above example, where we added conditional visibility to the Shipping Address component in a Screen form.

In the same way, we can add conditional visibility to the Screen flow component in our Salesforce instance, making the flows more dynamic and organized.

You may like to read: