diff --git a/.pmd/apex-ruleset.xml b/.pmd/apex-ruleset.xml
index 40b3b07..0fede2a 100644
--- a/.pmd/apex-ruleset.xml
+++ b/.pmd/apex-ruleset.xml
@@ -1,6 +1,4 @@
-
-
-
-
-
+
+
+
+
@@ -277,7 +275,7 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
>
3
-
+
3
-
+
3
-
+
3
@@ -322,12 +320,12 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
-
-
+
+
3
-
+
3
diff --git a/.pmd/veritech-ruleset.xml b/.pmd/veritech-ruleset.xml
index 4545d60..b22498e 100644
--- a/.pmd/veritech-ruleset.xml
+++ b/.pmd/veritech-ruleset.xml
@@ -26,11 +26,10 @@
name="ClassReferenceCapitalization-ReferenceExpression"
language="apex"
message="References to classes should start with an uppercase character followed by lowercase characters"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
>
3
-
3
-
3
-
2
-
All the lists and maps are initialized to empty collections by the trigger framework to reduce the need for null checks.
### Recursion prevention
-By default, the trigger framework prevents recursion in order to avoid hitting governor limits. However, if you need to allow recursion in your triggers, modify the trigger handler initialization by passing an optional Boolean parameter.
+By default, the trigger framework prevents recursion in order to avoid exceeding governor limits. However, if you need to allow recursion in your triggers, execute the method `allowRecursion()` before calling `run()`.
```apex
trigger AccountTrigger on Account(before insert, after insert) {
- Boolean allowRecursion = true;
- new AccountTriggerHandler(allowRecursion).run();
+ new AccountTriggerHandler().allowRecursion().run();
}
```
diff --git a/examples/classes/AccountTriggerHandler.cls-meta.xml b/examples/classes/AccountTriggerHandler.cls-meta.xml
index df13efa..c01f643 100644
--- a/examples/classes/AccountTriggerHandler.cls-meta.xml
+++ b/examples/classes/AccountTriggerHandler.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/examples/classes/AccountTriggerHandlerHelper.cls-meta.xml b/examples/classes/AccountTriggerHandlerHelper.cls-meta.xml
index df13efa..c01f643 100644
--- a/examples/classes/AccountTriggerHandlerHelper.cls-meta.xml
+++ b/examples/classes/AccountTriggerHandlerHelper.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/examples/triggers/AccountTrigger.trigger-meta.xml b/examples/triggers/AccountTrigger.trigger-meta.xml
index 78d3f04..ede3aa9 100644
--- a/examples/triggers/AccountTrigger.trigger-meta.xml
+++ b/examples/triggers/AccountTrigger.trigger-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/force-app/main/default/classes/BaseTriggerHandler.cls b/force-app/main/default/classes/BaseTriggerHandler.cls
index 0169d2b..3575868 100644
--- a/force-app/main/default/classes/BaseTriggerHandler.cls
+++ b/force-app/main/default/classes/BaseTriggerHandler.cls
@@ -104,7 +104,7 @@ public abstract class BaseTriggerHandler {
}
//================================================================================
- // Virtual (overridable) methods, run method, and run helpers
+ // Virtual (overridable) methods
//================================================================================
@TestVisible
@@ -129,6 +129,15 @@ public abstract class BaseTriggerHandler {
protected virtual void afterUndelete() {
}
+ //================================================================================
+ // Public methods and helpers
+ //================================================================================
+
+ public BaseTriggerHandler allowRecursion() {
+ this.allowRecursion = true;
+ return this;
+ }
+
public void run() {
if (this.canRun()) {
this.registerRun();
diff --git a/force-app/main/default/classes/BaseTriggerHandler.cls-meta.xml b/force-app/main/default/classes/BaseTriggerHandler.cls-meta.xml
index f5e18fd..651b172 100644
--- a/force-app/main/default/classes/BaseTriggerHandler.cls-meta.xml
+++ b/force-app/main/default/classes/BaseTriggerHandler.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/force-app/main/default/classes/BaseTriggerHandlerTest.cls b/force-app/main/default/classes/BaseTriggerHandlerTest.cls
index 546a932..e0a0a26 100644
--- a/force-app/main/default/classes/BaseTriggerHandlerTest.cls
+++ b/force-app/main/default/classes/BaseTriggerHandlerTest.cls
@@ -179,7 +179,7 @@ private without sharing class BaseTriggerHandlerTest {
);
}
- // Virtual (overridable) methods, run method, and run helpers
+ // Virtual (overridable) methods
// Suppressing ApexUnitTestClassShouldHaveAsserts because there is no logic in the overridable methods
@SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
@@ -198,6 +198,26 @@ private without sharing class BaseTriggerHandlerTest {
Test.stopTest();
}
+ // Public methods and helpers
+
+ @IsTest
+ static void allowRecursion_noParameters_recursionEnabled() {
+ TestTriggerHandler triggerHandler = new TestTriggerHandler();
+ Assert.isFalse(
+ triggerHandler.allowRecursion,
+ 'Expected the class property "allowRecursion" to be false initially'
+ );
+
+ Test.startTest();
+ triggerHandler.allowRecursion();
+ Test.stopTest();
+
+ Assert.isTrue(
+ triggerHandler.allowRecursion,
+ 'Expected the class property "allowRecursion" to be true after the method call'
+ );
+ }
+
@IsTest
static void run_canRunFalse_methodsNotExecuted() {
TestTriggerHandlerWithOverridenMethods triggerHandler = new TestTriggerHandlerWithOverridenMethods();
diff --git a/force-app/main/default/classes/BaseTriggerHandlerTest.cls-meta.xml b/force-app/main/default/classes/BaseTriggerHandlerTest.cls-meta.xml
index f5e18fd..651b172 100644
--- a/force-app/main/default/classes/BaseTriggerHandlerTest.cls-meta.xml
+++ b/force-app/main/default/classes/BaseTriggerHandlerTest.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/force-app/main/default/classes/TriggerUtil.cls-meta.xml b/force-app/main/default/classes/TriggerUtil.cls-meta.xml
index f5e18fd..651b172 100644
--- a/force-app/main/default/classes/TriggerUtil.cls-meta.xml
+++ b/force-app/main/default/classes/TriggerUtil.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/force-app/main/default/classes/TriggerUtilTest.cls-meta.xml b/force-app/main/default/classes/TriggerUtilTest.cls-meta.xml
index f5e18fd..651b172 100644
--- a/force-app/main/default/classes/TriggerUtilTest.cls-meta.xml
+++ b/force-app/main/default/classes/TriggerUtilTest.cls-meta.xml
@@ -1,5 +1,5 @@
- 60.0
+ 61.0
Active
diff --git a/manifest/package.xml b/manifest/package.xml
index 2c1987e..9b3258b 100644
--- a/manifest/package.xml
+++ b/manifest/package.xml
@@ -7,5 +7,5 @@
TriggerUtilTest
ApexClass
- 60.0
+ 61.0
diff --git a/package.json b/package.json
index 9ea8662..9e84e00 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "veritech-trigger-framework",
"private": true,
- "version": "1.2.0",
+ "version": "1.3.0",
"description": "Veritech Trigger Framework",
"scripts": {
"lint": "eslint **/{aura,lwc}/**/*.js",
diff --git a/sfdx-project.json b/sfdx-project.json
index e51485c..2f080fb 100644
--- a/sfdx-project.json
+++ b/sfdx-project.json
@@ -12,5 +12,5 @@
"name": "veritech-trigger-framework",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
- "sourceApiVersion": "60.0"
+ "sourceApiVersion": "61.0"
}