A Better Way to Bypass Data Validation

posted Oct 30, 2019, 9:53 AM by Ezra Kenigsberg   [ updated Nov 5, 2020, 7:23 AM ]
Q: "How do I make a record bypass Data Validation?"

A: The Clever Way:
  1. create a checkbox called "Toggle Me to Bypass Validation" (or something like it); and
  2. change your Validation Rules to ignore records where "Toggle Me to Bypass Validation" has changed--add a clause like NOT(ISCHANGED(Toggle_Me_to_Bypass_Validation__c)).
You're done!

In the past, folks implemented this the Adequate Way:
  1. create a checkbox called "Bypass Validation Rules for this Record" (or something like it);
  2. change your Validation Rules to ignore records where "Bypass Data Validation for this Record" is TRUE--add a clause like NOT(Bypass_Validation_Rules_for_this_Record__c); and
  3. create a Workflow Rule to change "Bypass Data Validation for this Record" back to FALSE whenever it's set to TRUE.
The problem with this approach: step 3.
  • The Workflow Rule changes the record AGAIN, which--depending on your config--could cause logic to re-run. suboptimal.
  • The Clever Way only touches the record once.
  • If you need to programmatically bypass Validation Rules for an existing record, set the record's "Toggle Me to Bypass Validation" to NOT(Toggle_Me_to_Bypass_Validation__c) in your Workflow, Process Builder, Flow, or Apex logic.
Props to Hanna Martynenko for the idea!
Comments