Validation flows for wins

The record-triggered flows with Custom Error element has been introduced a while back (Winter ’24 actually). I immediately saw their benefits but didn’t see many use-cases I would need them for.

The first use-case, when it was tempting, was a requirement to allow progress of opportunity into next stage only when products are added. Great use-case, but there is better OOTB functionality – the HasOpportunityLineItem which can be true or false.

But finally I got a bunch of great use-cases on current project, which are actually at the end linked together.

Use-Case #1 – validation of selected values

On account the customer has a multi-select picklist to choose industries, where the company is active. On opportunity they want to select for which specific industry it will be used. It is a single select and there is an obvious requirement for the user to be able to choose only something which is listed on the account.

Yeah, multi-select picklist, you can already smell it won’t be possible to check in validation rule. I mean it would be but you would need to list all the choices and compare, I didn’t find a way how to create a simple and universal validation rule.

Luckily, there is a before-save flow, where you can assign the multi-select into one variable and check whether it contains the value from opportunity, if not -> custom error.

Solved!

Use-Case #2 – limit the list of choices in the picklist

The list of the industries are fashionably long and when you are creating the opportunity you might not remember what is selected on the account. Especially if you are creating it from the menu or global action.

But hey, there is no way how you can make the picklist on opportunity dynamic, unless you want to develop it as custom component and then you have a challenge how to incorporate it nicely into the form.

Never mind, we have the flow above with the custom error and in the error we can list the industries from the account. Not a perfect solution as first save is rather a try, but on second save you know from which values you can choose.

Actually, with the right question we quickly found out that majority of accounts have just one industry. At that moment the solution was simple – in the before-save flow first check if there is only single industry, in such case set the industry on opportunity. If there are multiple check whether they selected the right one and if not give them a help text with suggestions what they can use.

Use-Case #3 – when progressing into next stage an activity has to be planned

Historically we would use something like DLRS to count the number of future activities linked to opportunity and build a validation rule linked to that field. Which would mean daily recalculation of all opportunities and other ugly things.

Luckily, before-save flow, which triggers when Stage is changed, query related activities with future date and if the collection is empty shows the custom error.

Similarly you can check whether this is first opportunity or another for the account and set/require the right type of opportunity.

Happy End

What started as super unhappy customer quickly iterated to something pretty usable what the customer is willing to accept as a nice solution. Thank you Salesforce and especially the Flow team for extending the platform with such goodies!

Leave a Reply