Skip to content

Commit a14efd1

Browse files
committed
Add Schema.SObjectType bypass functionality to TriggerBase class and corresponding tests
1 parent cfda671 commit a14efd1

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

trigger-actions-framework/main/default/classes/TriggerBase.cls

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* The `TriggerAction` interface defines the methods that should be implemented by trigger actions.
3434
*/
3535
@SuppressWarnings(
36-
'PMD.StdCyclomaticComplexity, PMD.CyclomaticComplexity, PMD.cognitivecomplexity, PMD.PropertyNamingConventions'
36+
'PMD.StdCyclomaticComplexity, PMD.CyclomaticComplexity, PMD.CognitiveComplexity, PMD.PropertyNamingConventions'
3737
)
3838
public inherited sharing virtual class TriggerBase {
3939
@TestVisible
@@ -136,6 +136,36 @@ public inherited sharing virtual class TriggerBase {
136136
return TriggerBase.bypassedObjects.contains(sObjectName);
137137
}
138138

139+
/**
140+
* @description This method bypasses the execution of the specified object.
141+
*
142+
* @param sObjectType The sObjectType of the object to bypass.
143+
*/
144+
public static void bypass(Schema.sObjectType sObjectType) {
145+
TriggerBase.bypassedObjects.add(sObjectType.getDescribe().getName());
146+
}
147+
148+
/**
149+
* @description This method clears the bypass for the specified object.
150+
*
151+
* @param sObjectType The sObjectType of the object to clear the bypass for.
152+
*/
153+
public static void clearBypass(Schema.sObjectType sObjectType) {
154+
TriggerBase.bypassedObjects.remove(sObjectType.getDescribe().getName());
155+
}
156+
157+
/**
158+
* @description This method checks if the specified object is bypassed.
159+
*
160+
* @param sObjectType The sObjectType of the object to check the bypass for.
161+
* @return True if the object is bypassed, false otherwise.
162+
*/
163+
public static Boolean isBypassed(Schema.sObjectType sObjectType) {
164+
return TriggerBase.bypassedObjects.contains(
165+
sObjectType.getDescribe().getName()
166+
);
167+
}
168+
139169
/**
140170
* @description This method clears all bypasses.
141171
*/

trigger-actions-framework/main/default/classes/TriggerBaseTest.cls

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,38 @@ private class TriggerBaseTest {
295295
);
296296
}
297297

298+
@IsTest
299+
private static void bypassWithSObjectTypeShouldSucceed() {
300+
TriggerBase.bypass(Schema.Account.SObjectType);
301+
302+
System.Assert.isTrue(
303+
TriggerBase.bypassedObjects.contains(ACCOUNT),
304+
BYPASSES_SHOULD_BE_CONFIGURED_CORRECTLY
305+
);
306+
}
307+
308+
@IsTest
309+
private static void clearBypassWithSObjectTypeShouldSucceed() {
310+
TriggerBase.bypass(Schema.Account.SObjectType);
311+
312+
TriggerBase.clearBypass(Schema.Account.SObjectType);
313+
314+
System.Assert.isFalse(
315+
TriggerBase.bypassedObjects.contains(ACCOUNT),
316+
BYPASSES_SHOULD_BE_CONFIGURED_CORRECTLY
317+
);
318+
}
319+
320+
@IsTest
321+
private static void isBypassedWithSObjectTypeShouldSucceed() {
322+
TriggerBase.bypass(Schema.Account.SObjectType);
323+
324+
System.Assert.isTrue(
325+
TriggerBase.isBypassed(Schema.Account.SObjectType),
326+
BYPASSES_SHOULD_BE_CONFIGURED_CORRECTLY
327+
);
328+
}
329+
298330
@IsTest
299331
private static void offsetRowsShouldWork() {
300332
TriggerBase.offsetExistingDmlRows();

0 commit comments

Comments
 (0)