3

I am trying to figure out what is calling my before update twice. Cannot see what is causing this.

Background

Object: Case Workflow Rules: All disabled PB: All disabled Case Assignment Rules: All disabled

Any update on the case object is call my before update method twice.

See log: Search for DEBUG/MG is this firing multiple times? Debug Log

Same code in dev org only fires once. Stumped?

Case trigger (only one)

    trigger CaseTrigger on Case(before insert, after insert, before update, after update, after delete, after undelete) {
    // Run Case Trigger Handler
    new CaseTriggerHandler().run();
}

Handler class

  public class CaseTriggerHandler extends TriggerHandler {

   public CaseTriggerHandler(){
    }

    public override void beforeInsert() {

}


    public override void beforeUpdate() {
        System.debug(LoggingLevel.ERROR, 'DEBUG/MG is this firing multiple times?'
    }

}
16
  • Any chance that you update your Case in your AfterUpdate? If so, look into a so-called trigger stopper: Basically a static variable that has to be false for your trigger logic to run, and which you set to true in your first run. May 4, 2015 at 14:12
  • Nope, nothing apart from debug statements just this: public override void beforeUpdate() { System.debug(LoggingLevel.ERROR, 'DEBUG/MG is this firing multiple times?'); } public override void afterUpdate() { System.debug(LoggingLevel.ERROR, ' afterUpdate - DEBUG/MG is this firing multiple times?'); } May 4, 2015 at 14:14
  • No active workflows either? May 4, 2015 at 14:17
  • 2
    Oh, that was a silly question since you already posted that in your question.. :-) Could you possibly update it and add your code, so we can have a look? (Trigger + Handler) May 4, 2015 at 14:25
  • 1
    What is the code of TriggerHandler.run(), or CaseTriggerHandler.run() (whichever one is being called from the trigger. And is this executing on a single record (not a batch of >200 which would execute your trigger logic a second time)? as Peter grasps at straws
    – pchittum
    May 5, 2015 at 9:10

3 Answers 3

1

Looking at your debug log, you are insert a Log__c custom object. If that log is the master-detail child of Case, then it could trigger an update on Case.

See number 17 here: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

1
  • Log object is standalone, not connected directly to any object. Jun 7, 2015 at 20:23
1

In your comment you said:

Nope, nothing apart from debug statements just this: public override void beforeUpdate() { System.debug(LoggingLevel.ERROR, 'DEBUG/MG is this firing multiple times?'); } public override void afterUpdate() { System.debug(LoggingLevel.ERROR, ' afterUpdate - DEBUG/MG is this firing multiple times?'); }

There is the code in this comment:

public override void beforeUpdate() { 
    System.debug(LoggingLevel.ERROR, 'DEBUG/MG is this firing multiple times?'); 
} 
public override void afterUpdate() { 
    System.debug(LoggingLevel.ERROR, ' afterUpdate - DEBUG/MG is this firing multiple times?'); 
}

And I don't see afterUpdate - DEBUG/MG is this firing multiple times? log in your debug log. Can it be that you didn't save the afterUpdate - part and it just prints 1 line for BEFORE and 1 line for AFTER update?

P.S. It was too long to post as a comment, so I had to post it as an answer

1

The trigger is firing on Before AND After event.

You should add some logic like :

if (Trigger.isBefore) {
new CaseTriggerHandler().run();
}

if(Trigger.isAfter) {
//do nothing
}

1
  • The point of the TriggerHandler class is that it is supposed to handle that sort of stuff. We don't know how it was implemented and so would have no idea if this is the case or not.
    – dphil
    Oct 29, 2015 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .