I presume the following may not be possible however I thought I'd check all the same. If I have 2 classes "class A" & "Class B", Is is possible in Apex to determine in "class B" if an instance of "class B" is currently executing (and vice-versa)?
Thanks in advance for any help on this.
I think you could use a global static variable as a flag. Set one when class B starts to execute, and you can read it from within class A, unset it when class B finishes executing. Here is an example of using such a flag:Suppose you had the following class:
public class p {
public static boolean firstRun = true;
}
A trigger that uses this class could then selectively fail the first run of the trigger:
trigger t1 on Account (before delete, after delete, after undelete) {
if(Trigger.isBefore){
if(Trigger.isDelete){
if(p.firstRun){
Trigger.old[0].addError('Before Account Delete Error');
p.firstRun=false;
}
}
}
}