Scenario: I have two objects - Object A and Object B.Object A has recursion checking mechanism using Static Boolean variables covering different events(IsBeforeUpdate,IsBeforeInsert etc..) I have two apex classes (Class 1 and Class 2) running on Object B that updates Object A on after update.
Question: Let us say an update operation happens on Object B. whats happens to the Static Boolean (IsBeforeUpdate on Object A) will it be set to false by the first class 1 ? and second class 2 will not be able do its update on Object A? if this is true , how can i make sure both my class 1 and 2 from Object B update Object A?
//MasterTaskTrigger
if (trigger.isUpdate && trigger.isAfter)
{
handler.afterUpdate(trigger.old, trigger.oldMap, trigger.new, trigger.newMap);
system.debug('inside After Update');
}
//This is an handler for Task Object
public class TriggerhandlerTask extends TriggerHandler
{
public void afterUpdate(List<Task> originalTask,Map<ID, Task> originalTaskMap,List<Task>updatedTask,Map<ID, Task> updatedTaskMap)
{
if(afterUpdateHasRun())
{
return;
}
//Call Class 1 - has logic to update Object A
Class1 Cs = new Class1();
//Call Class 2 - has logic to update Object A
Class2 Cs = new Class2();
}
}
//this handler is extended across all other objects Triggerhandlers
public virtual class TriggerHandler
{
public static boolean isBeforeInsertFirstRun = true;
public static boolean isBeforeUpdateFirstRun = true;
public static boolean isBeforeDeleteFirstRun = true;
public static boolean isAfterInsertFirstRun = true;
public static boolean isAfterUpdateFirstRun = true;
public static boolean isAfterDeleteFirstRun = true;
public static boolean isAfterUndeleteFirstRun = true;
protected boolean beforeInsertHasRun()
{
if (isBeforeInsertFirstRun)
{
return isBeforeInsertFirstRun = false;
System.debug('---->isBeforeInsertFirstRun'+isBeforeInsertFirstRun);
}
return true;
}
protected boolean beforeUpdateHasRun()
{
if (isBeforeUpdateFirstRun)
{
return isBeforeUpdateFirstRun = false;
System.debug('---->beforeUpdateHasRun'+beforeUpdateHasRun);
}
return true;
}
}