function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ross McLeod 3Ross McLeod 3 

Complex Business Rules

Hi

I have a requirement that when a child account is saved a validation rule needs to check against a filed on the top level account. 

I can do this via a trigger because I can select the clients then recursively loop up to the top client. However I was looking at doing in a flow and wondered how you can raise an error out of the flow to show stop the process and show to the user there is a rule that has been hit?

I read somewhere that auto launched flow should be able to complete with no issue. So my question is really what is the recommended approach to dealing with complex business rules that can not be done using validation rules.

Thanks
Best Answer chosen by Ross McLeod 3
Kanav TechfineryKanav Techfinery
Hi Ross,

Hope you're well. 
For slightly complex requirements that lie between Validation Rules and trigger, you can try exploring 'Before-Save' flows. You can check out my blog post where I demostrate this use case:

https://techfinery.com/nocode-validation-with-before-save-flows/

Look forward to hearing back!

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Ross,

Greetings!

Yes,you can create the validation rule in Flow.Please check the sample flow with the step by step procedure to achieve the same.

https://automationchampion.com/tag/validation-rule-in-flow/

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Kanav TechfineryKanav Techfinery
Hi Ross,

Hope you're well. 
For slightly complex requirements that lie between Validation Rules and trigger, you can try exploring 'Before-Save' flows. You can check out my blog post where I demostrate this use case:

https://techfinery.com/nocode-validation-with-before-save-flows/

Look forward to hearing back!
This was selected as the best answer
Ross McLeod 3Ross McLeod 3
Hi Kanav

Thanks for the heads up that would work. Couple of follow up questions:

1. If I put checkboxes on the object do they have to be visible on the page layout assigned to the user for this to work? 
2. If I have a number of these rules is it better to have them in a trigger where they can be unit tested. Especially as the rate of change with the rules is low.

I guess what I'm trying to work out is what the best solution is. We have the in house skill to build the trigger solution or the flow solution.

Any opinions on this would be appreciated?
Kanav TechfineryKanav Techfinery

Hi Ross,

Great questions:

 

1. If I put checkboxes on the object do they have to be visible on the page layout assigned to the user for this to work? 
KK: The checkboxes do not have to be on the page layout. As for Field level security, it will be a good test to see if the Before-save flow is able to check the checkbox even if the Running user does NOT have Read/Edit access to the Field. My hunch is that the User should be able to update the checkbox even without Field access. 

2. If I have a number of these rules is it better to have them in a trigger where they can be unit tested. Especially as the rate of change with the rules is low.
KK: As always with Salesforce, it depends. Personally, if I have upto 5 rules on an object, I would stick to before-save flows. They are easily unit test-able. You could write Apex tests - for covering the larger/end-2-end scenario - and check whether you are getting the expected error from the before-save flow.

When I would choose before-save flows  -> Less than 5 rules on an object with static error messages (as they use standard validation rules with a  static message)
When I would choose Apex triggers -> More than 5 rules on an object OR if I would like to make the validation error messages dynamic.