Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public TriggetPhase {
  2.  
  3. public enum ContextPhase {
  4. AFTER, BEFORE
  5. }
  6.  
  7. public enum ContextOperation {
  8. INSERT, UPDATE, DELETE, UNDELETE
  9. }
  10.  
  11. public ContextPhase phase {
  12. get {
  13. if (phase == null) {
  14. if (Trigger.isBefore) {
  15. phase = ContextPhase.BEFORE;
  16. } else if (Trigger.isAfter) {
  17. phase = ContextPhase.AFTER;
  18. }
  19. }
  20. }
  21.  
  22. private set;
  23. }
  24.  
  25. public ContextOperation operation {
  26. get {
  27. if (operation == null) {
  28. if (Trigger.isInsert) {
  29. operation = ContextOperation.INSERT;
  30. } else if (Trigger.isUpdate) {
  31. operation = ContextOperation.UPDATE;
  32. } else if (Trigger.isDelete) {
  33. operation = ContextOperation.DELETE;
  34. } else if (Trigger.isUndelete) {
  35. operation = ContextOperation.UNDELETE;
  36. }
  37. }
  38. }
  39.  
  40. private set;
  41. }
  42.  
  43. .....
  44.  
  45. }
  46.  
  47. public TriggerControlService {
  48.  
  49. public void execute(...) {
  50.  
  51. ...
  52. try {
  53.  
  54. checkContext();
  55.  
  56. if (triggerPhase.phase == TriggetPhase.ContextPhase.BEFORE) {
  57.  
  58. } else if (triggerPhase.phase == TriggetPhase.ContextPhase.AFTER) {
  59.  
  60. }
  61. } catch (Exception e) {
  62. System.debug(LoggingLevel.Error, '');
  63. }
  64.  
  65. ...
  66. }
  67.  
  68. private void checkContext() {
  69. if (triggerPhase.phase == null
  70. || triggerPhase.operation == null) {
  71.  
  72. throw new TriggerControlException('This context is not a trigger context');
  73. }
  74. }
  75.  
  76. private void performBefore(...) {
  77. if (triggerPhase.operation == TriggetPhase.ContextOperation.INSERT) {
  78.  
  79. } else if (triggerPhase.operation == TriggetPhase.ContextOperation.UPDATE) {
  80. } ...
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement