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
Rajwant SainiRajwant Saini 

stop trigger to fire from scheduled job

Hi Please help
I have a scheduled job which updates Accounts object data or insert new data in salesforce.
Also  I have a trigger which is AFTER INSERT and AFTER UPDATE on ACCOUNT object.

I do not want this trigger to fire when schedule job runs.
SO i did:

   if(!System.isScheduled()){    
    if (trigger.isUpdate){    
    Set<Id> setAccountNameChangedIds = new Set<id>();
        -------
         ---------
     }
  if (trigger.isInsert){    
         -------
          ------
     }
}

BUT my trigger is getting fired each time scheduled job runs.
Please help how do I stop the trigger to fire from scheduled job. I do not want to deactivate the trigger.

I just want it should not fire when scheduled job runs.

Please help!
 
RKSalesforceRKSalesforce
Hi Rajwani,

Please use below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm

You can use below code:
if(isExecuting){    
    if (trigger.isUpdate){    
    Set<Id> setAccountNameChangedIds = new Set<id>();
        -------
         ---------
     }
  if (trigger.isInsert){    
         -------
          ------
     }
}

Please mark as best answer if helped.

Regards,
Ramakant