Formula Resources in Criteria Conditions—Yes or No?

Salesforce Flow is a powerhouse for automation. And when it comes to building smart, dynamic Flows, Formula Resources play a critical role. They compute values for create, update and action elements, and calculate parameters to compare to in criteria conditions. But how exactly do they work? And where should you use them?

SurveyVista: Effortless Data Collection to Action

In this post, we’ll break down their use and explore whether we should be using them in criteria logic across various Flow elements.

What is a Formula Resource?

A Formula Resource in Flow is like a mini-calculator that evaluates to a single value (text, number, Boolean, or date) based on logic you define. Think of it like a formula field on an object, but used inside your Flow instead of the database.

Formula Resources use the same syntax as formula fields, including functions, operators, and references to variables or record fields.

Where Are Formula Resources Used?

You can use them in many flow elements, such as:

Decision Elements

You can use Formula Resources in Decision outcomes to:
  • Evaluate complex conditions in a clean and reusable way.
  • Reference a single Boolean formula instead of adding it to multiple outcomes.
Example:
You might define a Formula Resource like: {!IsHighValueOpportunity} = {!Opportunity.Amount} > 100000
Then in your Decision element, you simply check if IsHighValueOpportunity = TRUE.

Update Elements

You can use formula resources in two ways in update elements:
  • On the right side of a criteria condition that determines when to execute the update.
  • On the right side of the field update to calculate and determine the new field value.

Get and Collection Filter Elements

You can use a formula resource on the right side of the criteria condition to specify which records you want in your output while configuring these elements.

Free Mentorship With Talent Stacker

Assignment, Create and Action Elements

While these elements don’t have criteria conditions in them, they can utilize formula resources to compute field and the parameter values.

Example:

You might use a Formula Resource like: {!TodayPlusSeven} = {!$Flow.CurrentDate} + 7
And then assign this value to the due date of a task or close date of an opportunity.

Benefits of Using Formula Resources in Criteria

Using Formula Resources gives you an advantage when you want to use them again in your flow. Reusability would be the biggest advantage of using a formula resource in a criteria condition rather than building the logic in the element line by line.

One could also argue that formula resources can handle complex logic better in certain situations.

Formula Resource or Multi-line Criteria Conditions

Instead of inserting formula resources in criteria for decisions and updates, you should consider building multi-line conditions combined with AND and OR operators. Using formula resources may have negative performance impact on larger flows with many of them. They are computed several times throughout the execution of the flow, which may be more resource draining than building a multi-line criteria condition inside one element.

If you are not worried about performance in your particular case, or this is not a record-triggered flow, then this may not be a concern.

There are several other advantages of building criteria conditions directly inside an element like a decision:

  • Readability: Even if you find a very descriptive name for your formula resource and add a description to it, it becomes a black box that you have to open, in order to understand the logic.
  • Maintenance: Unless you use the same formula resource more than once in your flow, clicking through multiple formula resources to understand and update the logic can be more difficult than doing the same inside the element.
  • Ease of debug: Your debug log can show more detail about how your criteria condition logic evaluates the data compared to the a formula resource that just returns a boolean value (true/false).

Pro Tip 1: When setting up formula resources, prefer returning a value to compare to, rather than a boolean value if your use case supports this. Example: Prefer returning the difference of days between today and the record created date, rather than setting up an IsRecent boolean formula resource that returns true when the record was created in the last seven days.

Pro Tip 2: If you need a not contains criteria condition and only see contains, you can go to custom logic in most cases and add a NOT() around the criteria condition with the contains clause.

Conclusion

Use formula resources only when you definitely need them. Consider setting up multi-line conditions combined with AND and OR operators instead. Name them clearly and add comments and descriptions.

If your use case requires setting up complex formula resources, break down the formula in smaller pieces and test them separately, before you put the whole thing together. Sometimes it may make sense to create a formula field on the object temporarily, when building a complex formula. This way, you can see the result of the computation immediately on multiple records (leverage list views).

Remember that the comment syntax used for Apex also works in formula resources. You can use it to add comments to complex formulas, like this: /* Example: This comment can wrap over multiple lines. */.

This post is part of our Best Series collection. Read the other posts HERE.

Explore related content:

How To Build Flex and Field Generation Prompt Templates in the Prompt Builder

Start Autolaunched Flow Approvals From A Button

Can You Start With a Loop Inside Your Schedule-Triggered Flow?

Display Product and Price Book Entry Fields in the Same Flow Data Table

A Comparative Look at Flow Decision Elements in Salesforce

Andy Engin Utkan

Andy Engin Utkan is a Salesforce MVP with 24 certifications. He is the founder of Salesforce Consulting Partner BRDPro Consulting. Utkan is a consultant, trainer, and content creator, focusing on automating business processes using Salesforce flow. He is recognized for his expertise in Salesforce flow, providing guidance through various courses and contributing actively to the Salesforce community.
Back to top button

Discover more from Salesforce Break

Subscribe now to keep reading and get access to the full archive.

Continue reading