+ Start a Discussion
Travis DvorakTravis Dvorak 

Bypass trigger while using data loader?

Good day experts.  I have a trigger that I created to replace our orgs validation rules.  I need a way to bypass them while doing doing a mass update via data loader.  I did end up getting that figured out by adding logic to the validation trigger, however, I'm now having an issue updating a field after the update.

if(c.skip_validation__c = true){

so when the case update is loaded, I add the value of "skip_validation__c" to true, which will bypass it.  At the end of the validation trigger (or a separate one), I would like to update any case that has "case_validation__c" as "true" and update it false, so it doesn't bypass the validation trigger going forward.  How would I accomplish this?  Tried via process builder, but doesn't work since it would be saved not meeting the criteria.  
Natarajan _Periyasamy__cNatarajan _Periyasamy__c
Hi Travis,

The best way to do this is to create a custom settings called 'Load Lean Settings' (hierarchical) which should have a boolean field called 'No Triggers' (Or whatever so).

a. For the data loading user, configure it (No Triggers) to True
b. Update your trigger code to something similar to below
//Get the Load Lean Settings for the current user (Dynamic)
Load_Lean_Settings__c notriggers = Load_Lean_Settings__c.getInstance(UserInfo.getUserId());

if (notriggers == null || (notriggers != null && !notriggers.No_Triggers__c)) {
 //Your Trigger - Validation Logic