+ Start a Discussion
vandana rajuvandana raju 

bypass trigger and validation rule when using dataloader

Hi
I am performing a data import through dataloader so I need to disable validation rules and trigger.
I know how to create a custom setting , type=Hierarchy but I am unable to frame the code for validation rule and trigger.

any help will be greatly appreciated.

Thanks
Vandana
Akhil AnilAkhil Anil
Hi Vandana,

Simply create a Custom field in your object of the type Checkbox called as "Bypass Valdiation". Then set this value to TRUE when you update the records through the dataloader and tweak your valudation rule like this. This will ensure that the validation rule is not invoked when you update/insert through dataloader.
 
AND(
NOT(Bypass_Validation__c),
Your existing conditions here
)

That should work !
pkpnairpkpnair
Hi Vandana,
It is a better practice to have a custom settings in your org where you can have check box fields for each objects to turn on/off your validations/triggers. 
-Prakash
vandana rajuvandana raju
Hi akhil
Is it the same for bypassing trigger also?

Vandana
 
Akhil AnilAkhil Anil
Hi Vandana,

Yes. However with the approach I mentioned it would be a bit difficult to handle it in triggers. Instead you can go with Custom setting approach which is explained in detailed in the below link

https://www.linkedin.com/pulse/20140824140147-19516399-how-to-disable-enable-all-validation-rules-for-data-loading-in-salesforce
pkpnairpkpnair

For example: Create a custom settings ObjectAutomationController__c. 
Add a checkbox OpportunityValidationRule__c for opportunity validations tun on/off. Now in your validation rules do the following.
IF($Setup.ObjectAutomationController__c.OpportunityValidationRule__c == true) AND( Put your validation rule here)

Add a checkbox OpportunityTrigger__c for opportutnity triggers tun on/off.. Now in your triggers do the the following
if(ObjectAutomationController__c.getInstance().OpportunityTrigger__c) { Put your trigger logic here }

vandana rajuvandana raju
Hi pkpnair
 I have a doubt. If we are using custom settings to disable trigger then as per documentation it applies profile level so multiple users having same
 profile could be affected. so is this allowed?

Thanks
vandana
pkpnairpkpnair
Vandana,
You can click on the "Manage" button on the Custom Setting definition. Set the check boxes as neeed.  The values are by default populated for organization level. You will see the Location: <Oraganization name>. If you want to override the values for any profiles or users, you can scrool down and click "new" to add a user/profile and set specific values there. This will over ride the default org values for that profile/user speicfically.

Does this help?
-Prakash