Skip to content

Commit

Permalink
Merge pull request #3 from VeritechConsulting/release/1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
frankpeleato authored Aug 26, 2024
2 parents 1623d0c + 2c2bffc commit cf83d9d
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 36 deletions.
22 changes: 10 additions & 12 deletions .pmd/apex-ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- From the Apex PMD repo
https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.xml -->
<ruleset
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -66,10 +64,10 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
</properties>
</rule>
<rule ref="category/apex/design.xml/CognitiveComplexity">
<properties>
<property name="classReportLevel" value="50" />
<property name="methodReportLevel" value="15" />
</properties>
<properties>
<property name="classReportLevel" value="50" />
<property name="methodReportLevel" value="15" />
</properties>
</rule>

<!-- PERFORMANCE -->
Expand Down Expand Up @@ -277,7 +275,7 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
>
<priority>3</priority>
<properties>
</properties>
</properties>
</rule>
<rule
ref="category/apex/codestyle.xml/ForLoopsMustUseBraces"
Expand All @@ -292,12 +290,12 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
<rule ref="category/apex/errorprone.xml/EmptyCatchBlock" message="Avoid empty catch blocks">
<priority>3</priority>
<properties>
</properties>
</properties>
</rule>
<rule ref="category/apex/errorprone.xml/EmptyIfStmt" message="Avoid empty 'if' statements">
<priority>3</priority>
<properties>
</properties>
</properties>
</rule>
<rule ref="category/apex/errorprone.xml/EmptyWhileStmt" message="Avoid empty 'while' statements">
<priority>3</priority>
Expand All @@ -322,12 +320,12 @@ https://github.com/ChuckJonas/vscode-apex-pmd/blob/master/rulesets/apex_ruleset.
</properties>
</rule>

<!-- Visual Force -->
<rule ref="category/vf/security.xml/VfCsrf">
<!-- Visual Force -->
<rule ref="category/visualforce/security.xml/VfCsrf">
<priority>3</priority>
</rule>

<rule ref="category/vf/security.xml/VfUnescapeEl">
<rule ref="category/visualforce/security.xml/VfUnescapeEl">
<priority>3</priority>
</rule>
</ruleset>
13 changes: 4 additions & 9 deletions .pmd/veritech-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<priority>3</priority>
<properties>
<property name="version" value="2.0" />
<property name="xpath">
<value>
<![CDATA[
Expand All @@ -51,7 +50,6 @@
or lower-case(@Image)='string'
or lower-case(@Image)='time'
or lower-case(@Image)='system'
or lower-case(@Image)='database'
or lower-case(@Image)='test'
or lower-case(@Image)='assert'
or lower-case(@Image)='messaging'
Expand All @@ -67,11 +65,10 @@
name="ClassReferenceCapitalization-ModifierNode"
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"
>
<priority>3</priority>
<properties>
<property name="version" value="2.0" />
<property name="xpath">
<value>
<![CDATA[
Expand All @@ -93,11 +90,10 @@
name="ClassReferenceCapitalization-Parameter"
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"
>
<priority>3</priority>
<properties>
<property name="version" value="2.0" />
<property name="xpath">
<value>
<![CDATA[
Expand All @@ -119,11 +115,10 @@
name="UsageOfSystemAssert"
language="apex"
message="Use the Assert class in test methods instead of System.assert"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
>
<priority>2</priority>
<properties>
<property name="version" value="2.0" />
<property name="xpath">
<value>
<![CDATA[
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.3.0 - 2024-08-26
### Added
- New method `allowRecursion()` to simplify the setup of triggers requiring recursion.

### Changed
- Updated PMD rulesets to comply with the latest PMD release.
- Updated Salesforce API versions.
- Updated package versions in `package.json`.
- Updated README.

## 1.2.0 - 2024-02-20
### Added
- Included `examples` as a packaged directory in `sfdx-project.json` to make it deployable.
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ The following context variables have been retrieved from `Trigger` and are avail
> 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();
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/classes/AccountTriggerHandler.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion examples/classes/AccountTriggerHandlerHelper.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion examples/triggers/AccountTrigger.trigger-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexTrigger>
11 changes: 10 additions & 1 deletion force-app/main/default/classes/BaseTriggerHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public abstract class BaseTriggerHandler {
}

//================================================================================
// Virtual (overridable) methods, run method, and run helpers
// Virtual (overridable) methods
//================================================================================

@TestVisible
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
22 changes: 21 additions & 1 deletion force-app/main/default/classes/BaseTriggerHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion force-app/main/default/classes/TriggerUtil.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion manifest/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<members>TriggerUtilTest</members>
<name>ApexClass</name>
</types>
<version>60.0</version>
<version>61.0</version>
</Package>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"name": "veritech-trigger-framework",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "60.0"
"sourceApiVersion": "61.0"
}

0 comments on commit cf83d9d

Please sign in to comment.