Skip to content

Commit 468360d

Browse files
authored
Merge pull request kevinohara80#27 from TrangOul/patch-1
Update TriggerHandler.cls
2 parents 8211266 + 9237c78 commit 468360d

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/classes/TriggerHandler.cls

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,36 @@ public virtual class TriggerHandler {
3030
// main method that will be called during execution
3131
public void run() {
3232

33-
if(!validateRun()) return;
33+
if(!validateRun()) {
34+
return;
35+
}
3436

3537
addToLoopCount();
3638

3739
// dispatch to the correct handler method
38-
if(this.context == TriggerContext.BEFORE_INSERT) {
39-
this.beforeInsert();
40-
} else if(this.context == TriggerContext.BEFORE_UPDATE) {
41-
this.beforeUpdate();
42-
} else if(this.context == TriggerContext.BEFORE_DELETE) {
43-
this.beforeDelete();
44-
} else if(this.context == TriggerContext.AFTER_INSERT) {
45-
this.afterInsert();
46-
} else if(this.context == TriggerContext.AFTER_UPDATE) {
47-
this.afterUpdate();
48-
} else if(this.context == TriggerContext.AFTER_DELETE) {
49-
this.afterDelete();
50-
} else if(this.context == TriggerContext.AFTER_UNDELETE) {
51-
this.afterUndelete();
40+
switch on this.context {
41+
when BEFORE_INSERT {
42+
this.beforeInsert();
43+
}
44+
when BEFORE_UPDATE {
45+
this.beforeUpdate();
46+
}
47+
when BEFORE_DELETE {
48+
this.beforeDelete();
49+
}
50+
when AFTER_INSERT {
51+
this.afterInsert();
52+
}
53+
when AFTER_UPDATE {
54+
this.afterUpdate();
55+
}
56+
when AFTER_DELETE {
57+
this.afterDelete();
58+
}
59+
when AFTER_UNDELETE {
60+
this.afterUndelete();
61+
}
5262
}
53-
5463
}
5564

5665
public void setMaxLoopCount(Integer max) {
@@ -147,10 +156,7 @@ public virtual class TriggerHandler {
147156
if(!this.isTriggerExecuting || this.context == null) {
148157
throw new TriggerHandlerException('Trigger handler called outside of Trigger execution');
149158
}
150-
if(TriggerHandler.bypassedHandlers.contains(getHandlerName())) {
151-
return false;
152-
}
153-
return true;
159+
return !TriggerHandler.bypassedHandlers.contains(getHandlerName());
154160
}
155161

156162
@TestVisible
@@ -204,11 +210,7 @@ public virtual class TriggerHandler {
204210
}
205211

206212
public Boolean exceeded() {
207-
if(this.max < 0) return false;
208-
if(this.count > this.max) {
209-
return true;
210-
}
211-
return false;
213+
return this.max >= 0 && this.count > this.max;
212214
}
213215

214216
public Integer getMax() {

0 commit comments

Comments
 (0)