Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public TriggetPhase {
- public enum ContextPhase {
- AFTER, BEFORE
- }
- public enum ContextOperation {
- INSERT, UPDATE, DELETE, UNDELETE
- }
- public ContextPhase phase {
- get {
- if (phase == null) {
- if (Trigger.isBefore) {
- phase = ContextPhase.BEFORE;
- } else if (Trigger.isAfter) {
- phase = ContextPhase.AFTER;
- }
- }
- }
- private set;
- }
- public ContextOperation operation {
- get {
- if (operation == null) {
- if (Trigger.isInsert) {
- operation = ContextOperation.INSERT;
- } else if (Trigger.isUpdate) {
- operation = ContextOperation.UPDATE;
- } else if (Trigger.isDelete) {
- operation = ContextOperation.DELETE;
- } else if (Trigger.isUndelete) {
- operation = ContextOperation.UNDELETE;
- }
- }
- }
- private set;
- }
- .....
- }
- public TriggerControlService {
- public void execute(...) {
- ...
- try {
- checkContext();
- if (triggerPhase.phase == TriggetPhase.ContextPhase.BEFORE) {
- } else if (triggerPhase.phase == TriggetPhase.ContextPhase.AFTER) {
- }
- } catch (Exception e) {
- System.debug(LoggingLevel.Error, '');
- }
- ...
- }
- private void checkContext() {
- if (triggerPhase.phase == null
- || triggerPhase.operation == null) {
- throw new TriggerControlException('This context is not a trigger context');
- }
- }
- private void performBefore(...) {
- if (triggerPhase.operation == TriggetPhase.ContextOperation.INSERT) {
- } else if (triggerPhase.operation == TriggetPhase.ContextOperation.UPDATE) {
- } ...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement