Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a batch job that updates accounts. There is also an after trigger (just to make life more complicated).

I want that the trigger will not fire during the batch job.

I wrote a global validator class, and trying to control run's with it.

global class Validator_CLS{
    private static boolean blnAlreadyDone = false;

    public static boolean hasAlreadyDone(){ return blnAlreadyDone; }
    public static void setAlreadyDone() { blnAlreadyDone = true; }   

Batch works: calls the global class - sets parameter to true


public class SF2NSUpdateOpportunityNSId{

    public static void collectData(){

            system.debug('no need to run again');
            return ; 
...... Alot more code here

When trigger fires, it needs to NOT run if parameter is true.


trigger trgSF2NSAccount on Account (after update,after insert) {

    system.debug('trgSF2NSAccount + Validator_cls.hasAlreadyDone ' + Validator_cls.hasAlreadyDone());
        system.debug('no need to run again');
        return ; 
.... A LOT more code here as well

Something is wrong.

The trigger keeps firing

share|improve this question
are you sure you are not missing setting the value to true during batch like Validator_CLS.setAlreadyDone(); – snehakem Mar 6 '14 at 13:20

You can use !system.isBatch() in your trigger to check if it is fired from within a batch or not

share|improve this answer
This perfectly resolved my similar situation. Thanks Sven – pmvsdt Sep 24 '15 at 14:59
You are welcome. If this answers the question then please mark it as a correct answer. thx – Sven Delporte Sep 25 '15 at 7:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.