1

I'm trying to pass a value to a variable in an apex trigger from an apex controller in an effort to control whether the the code in the trigger is executed.

In myController initialization, I try to set this variable:

Controller:

public myController() {

        CaseTrigger.isComingFromEmail = true; 

} 

Trigger:

trigger CaseTrigger on Case (before insert){

    public static boolean isComingFromEmail = false;

    if (isComingFromEmail) {
        return;
    }
    else {
//Actual Processing Here
}

The error received on myController:

Variable does not exist: CaseTrigger

Related post:

Skip the execution of trigger

5

Triggers are not classes, and you shouldn't reference them like this. You should create a separate class to store your static variable, and then reference this class in both your controller and trigger.

  • To confirm, in the related post the recommendation by Sebastian is not valid? – S.B. May 19 at 20:24
  • 2
    I don't think so. But it does illustrates the pattern. I'd prefer Akram G's solution instead, since you can reuse it on other triggers latter as well. – Renato Oliveira May 19 at 20:26
  • Mihai Neagoe's post on salesforce.stackexchange.com/questions/61371/… is also a good example of the pattern that Sebastian tries to illustrate. – Renato Oliveira May 19 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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