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

1 Answer 1

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.

3
  • To confirm, in the related post the recommendation by Sebastian is not valid?
    – S.B.
    May 19, 2019 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. May 19, 2019 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. May 19, 2019 at 20:28

You must log in to answer this question.

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