function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Micky MMicky M 

Static flags

Hi all does anyone know why this class 

public class staticFlagsForRecursionTriggers 
    public static boolean firstRun = true;

Can't be seen by my trigger when i call a controller from a visual force page?

the trigger is :

if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate) && staticFlagsForRecursionTriggers.firstRun == TRUE)
        staticFlagsForRecursionTriggers.firstRun = FALSE;

staticFlagsForRecursionTriggers.firstRun is always false so the trigger isnt running.

Cyrus TalladenCyrus Talladen
Because of the nature of triggers they "trigger" when a certain event occurs (see Context variables).  So when you call a controller by accessing your page it doesnt necessarily fire the trigger unless you are making a dml transaction in the controller at which point the trigger will then fire.

Cyrus T
Micky MMicky M
Hi thats the thing, i am inserting records in the controller that im calling from my visualforce page, the page calls calls a method in my controller which  creates and instance of another class and calls a method which performs inserts which fire the trigger. The trigger isnt seeing a static class that im using to prevent recursion.
Cyrus TalladenCyrus Talladen
Well, if you were following SFDC best practices and have a trigger handler class, then your controller can call the method in the trigger handler.  I dont think it is possible for a controller to explicitly make a call to the trigger because, when triggers are declared, they are only used by the sObject internally outside of the developer's control.  Please read this doc: