Formulas in Salesforce flows are really cool. They are a unique type of variable, one that has multiple purposes.

Here’s one of my favorite methods to show just how cool they are: formulas are only evaluated at the moment they are used.

As an example, let’s say your flow has a decision element. If the flow goes left, it gets an Opportunity. If the logic goes right, it gets an Account. After this, the branches merge again into the same thread.

Visualize then, a formula field called “fCurrentId”, which uses values from both Gets. The formula could be IF(NOT(ISBLANK(Get Oppportunity.Id)), Get Oppportunity.Id, Account.Id) In simple terms this means, “If Opportunity.Id is valid, use it. Else use Account.Id”

  • If this formula field is used on the left branch, it will equal Opportunity.Id
  • If it’s used on the right branch, it will equal Account.Id
  • If it’s used after the branches are merged, it will equal the value of the branch it transversed

How cool is that? 🙂

The takeaway
Formula fields are cool because their value is only determined at the step where they are located.

Category:
Salesforce