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
parth sachi 7parth sachi 7 

How to Stop trigger fire during mass update via data loader ?

The requirement is to fire trigger in case of record update, but do not want to update record in-case of mass update i.e. bulk update via data loader. 
Anthony McDougaldAnthony McDougald
Good Evening Parth,
Hope that your day is off to an amazing start. Assuming that this is temporary, the easiest solution would be to change the trigger to inactive in a sandbox and deploy the inactive version in a changeset to your production org. Hope this helps and may God bless you abundantly.
Best Regards,
Anthony McDougald
Maharajan CMaharajan C
Hi Parthi,

1. use the custom label or custom setting to Switch ON/OFF the trigger. So while you perform the dataloader simply you can switch off the trigger and once the mass update is done you can Switch on the trigger with the help of the configuration.

Custom Label:     Name as:    switchOFFTrigger

Create the Custom Label.  If the Label Value is Yes => Switch OFF the Trigger. If the Label Value is No => Switch ON the Trigger. 

trigger accountTrigger on Account (after insert,after update) {
    if(System.Label.switchOFFTrigger == 'No')
    {
        if(Trigger.isInsert && Trigger.isAfter)
           {
        
           }
          else if(Trigger.isUpdate && Trigger.isAfter)
          {
        
          }
    }
}

Custom Setting:
 
Create the Custom Setting type as List.  Name as SwitchOffTrigger.
Create the Checkbox Field in Custom Setting.  Name as Swtich
Create the One record in Custom Setting with Name as bypassTrigger bydefault switch field should be unchecked.  If the bypassTrigger record switch has checked then bypass the Trigger like below.

trigger accountTrigger on Account (after insert) {
    SwitchOffTrigger__c myCS = SwitchOffTrigger__c.getValues('bypassTrigger');
    system.debug(' ### '+myCS.Swtich__c);
    if(!myCS.Swtich__c)
    {
         if(Trigger.isInsert && Trigger.isAfter)
        {
        
       }
    }
}


2.  Bypass the Mass update from trigger itself.

trigger accountTrigger on Account (after insert) {
    List<Account> accList = Trigger.New;
    if(accList.size() == 1)
    {
        if(Trigger.isInsert && Trigger.isAfter)
        {
            
        }
    }
}

 
Thanks,
Maharajan.C
Brijesh Yadav 113Brijesh Yadav 113
Hey maharajan c nice information thankyou to tell ( hindi paheliyan with answer (https://www.hindipaheliyanwithanswer.in) )
scox67scox67
Hey Parth,

As mentioned, you can add trigger logic to look at a custom label, setting, or metadata type. A simpler solution is to go to Settings | Apex Triggers and uncheck "Active" on the desired trigger. Maharajan's point 2 will not work, because it's impossible to know the source of data. A bulk import may be a single record, or a mass update via the UI or API may be multiple records.

I gave a Dreamforce presentation on triggers and have a book (http://force-code.com/about/) out that discusses lots of ways to create high-quality Apex code.

Best of luck!
~Steve