A sales manager suspected his Salesforce dashboard did not match the business. He called a meeting and found out that every rep had a personal Excel sheet. When he asked why, one rep opened an opportunity and clicked Save. Error. He filled in a required field. Another error. He changed the close date. One more. Then he told his manager he could do the same thing in Excel in 15 seconds. The IT team had spent months building validation rules to protect data quality, and got the opposite. I shared that story on LinkedIn today. The longer version, in Spanish, is on EGA Futura Discover.

One of the five questions I ask before creating a new validation rule is whether a before-save flow could fix the data instead. This post shows what that looks like.

Why a before-save flow runs first

A record-triggered flow set to optimize for Fast Field Updates runs before the record is saved. In the Salesforce order of execution, these flows run ahead of Apex before triggers and custom validation rules. So if the flow corrects a value, the validation rule evaluates the corrected value and the user never sees an error.

They run for every source that saves the record: the UI, the API, Data Loader. The same scope as a validation rule.

Example: a website without the protocol

A common rule on Account looks like this:

AND( NOT(ISBLANK(Website)), NOT(BEGINS(Website, "http")) ) 

Error message: "Website must start with http:// or https://". The rep pasted egafutura.com, which is fine for a human, and now has to fix it by hand.

The flow version:

  1. Create a record-triggered flow on Account, triggered when a record is created or updated.
  2. Entry condition: Website Is Null = False.
  3. Optimize the flow for: Fast Field Updates.
  4. Add a formula resource fxWebsite (Text):
IF( BEGINS({!$Record.Website}, "http"), {!$Record.Website}, "https://" & TRIM({!$Record.Website}) ) 
  1. Add an Assignment element: {!$Record.Website} Equals {!fxWebsite}.

There is no Update Records element. In a before-save flow you assign values to $Record and Salesforce saves them with the record.

Activate the flow, test it in a sandbox, and deactivate the validation rule. Keep the rule's formula in its description in case you need to bring it back.

Other rules that usually become flows

  • A code that must be uppercase: UPPER(TRIM({!$Record.Code__c})).
  • A tax ID typed with or without dashes: SUBSTITUTE({!$Record.Tax_Id__c}, "-", "").
  • A field that can be derived from another, such as a region from a country picklist, through a Decision element and one Assignment per branch.

When the rule should stay

If the value cannot be inferred, the flow has nothing to fix. A loss reason on a Closed Lost opportunity is a good example: only the rep knows it. In that case keep the rule, but make it hurt less:

  • Show the field only when it matters with Dynamic Forms visibility, and mark it required on the page so the rep fills it in before clicking Save.
  • Set the error location to the field instead of the top of the page.
  • Scope the formula with ISCHANGED(StageName) so it does not block edits to old records.

At EGA Futura we build a native ERP for Salesforce around the same idea: let the technology absorb the complexity so people can do their work.

The question I left on LinkedIn: how many validation rules in your Salesforce org are the result of poor design?

Juan Manuel Garrido, founder of EGA Futura