Skip to main content

Posts

Showing posts from March, 2021

Static and Instance Methods, Variables, and Initialization Code

Static methods, variables, and initialization code have these characteristics They’re associated with a class. They’re allowed only in outer classes. They’re initialized only when a class is loaded. They aren’t transmitted as part of the view state for a Visualforce page. Using Static Methods and Variables public class Parent {     public static boolean isRun = 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( Parent .isRun){                  Trigger.old[0].addError('Before Account Delete Error');                    Parent .isRun =false;              }  ...