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:


public myController() {

        CaseTrigger.isComingFromEmail = true; 



trigger CaseTrigger on Case (before insert){

    public static boolean isComingFromEmail = false;

    if (isComingFromEmail) {
    else {
//Actual Processing Here

The error received on myController:

Variable does not exist: CaseTrigger

Related post:

Skip the execution of trigger

1 Answer 1


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.
    Commented 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. Commented 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. Commented 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 .