[SalesForce] Validation rule Preventing Process Builder Field Update process

I have Two business requirements

1) Leadership team asked me to prevent updating of Sales Stages manually

2) Sales Stages should be updated as result of Logging of Activities

So, I came with following solution

First I have written Validation Rule, which is

AND( 
NOT(ISNEW()), 
ISCHANGED(StageName) 
)

this rule is working fine, nobody can modify sales stages anymore.

Now off to Process Builder

  • Object = Task
  • Criteria = Set Conditions

Conditions are

[Task].Status = Picklist Value = Completed

[Task].WhatID(related to) = starts with = 006 (opportunity object key prefix)

[Task].Subject = String = Call

Immediate Action

Update Records

  • Choose Related opportunity record

Criteria for updating record

Updated Records Meet all Conditions

stage = picklist = prospecting (1st stage)

Set New Field Values

Stage = picklist = Contacted (2nd Stage)

My process builder is working fine too…just that i have to disable validation rule otherwise process fails to execute.

Kindly guide me as to how to achieve these objectives.

Kind Regards
Prashant

Best Answer

Follow below steps to bypass validation rule in process builder:-

Implement a field which allows bypassing validation rules for Processes, on Opportunity, have a checkbox field BypassValidationForProcessBuilder__c, default unchecked, not shown on the Page Layout.

Adjust your Validation Rule to:

AND( NOT(Opportunity.BypassValidationForProcessBuilder__c) ,
NOT(ISNEW()), 
ISCHANGED(StageName) 
)
  • In your Process, in the immediate action block, first, use a record update for the concerned Opportunity record to set our Bypass field to TRUE. Within the same immediate action block, you can now have an action to update the stage name, use as many actions as needed. Then at the end have another update action to set the Bypass field back to FALSE. Within one immediate action block, the actions are done in order and separately.
  • By setting the flag back to false, you are making a field update. This will cause validation rules with boolean checkboxes such as Opportunity.BypassValidationForProcessBuilder__c = false to then make the validation rule true.
  • Alternatively, you could add Opportunity.BypassValidationForProcessBuilder__c = false && !ISCHANGED(Opportunity.BypassValidationForProcessBuilder__c) to the validation rule to bypass it.

reference:- https://help.salesforce.com/articleView?id=000247715&type=1

Hope it helps You.

Related Topic