Skip to content

Commit 56eff05

Browse files
authored
Enhance FormulaFilter and test classes for improved evaluation handling (#184)
- Update FormulaFilter to explicitly check for true in evaluation condition. - Add test case to handle scenarios where formula evaluation results in null. - Modify test classes to run in parallel for better performance.
1 parent ee05fd3 commit 56eff05

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ global class FormulaFilter {
103103
);
104104
toProcess.newSobject = record;
105105
toProcess.oldSobject = recordPrior;
106-
if ((Boolean) fx.evaluate(toProcess)) {
106+
if ((Boolean) fx.evaluate(toProcess) == true) {
107107
result.triggerNew.add(record);
108108
result.triggerOld.add(recordPrior);
109109
}

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@SuppressWarnings(
1717
'PMD.ApexUnitTestClassShouldHaveRunAs, PMD.AvoidGlobalModifier'
1818
)
19-
@IsTest
19+
@IsTest(IsParallel=true)
2020
global class FormulaFilterTest {
2121
private static final String ACCOUNT_SOBJECT_NAME = 'Account';
2222
private static final String EXCEPTION_SHOULD_BE_THROWN = 'An exception should be thrown';
@@ -327,6 +327,33 @@ global class FormulaFilterTest {
327327
);
328328
}
329329

330+
@IsTest
331+
private static void formulaEvaluatingToNullShouldBeTreatedAsFalse() {
332+
triggerNew[1].Description = 'example 1';
333+
configuration.Entry_Criteria__c = 'CONTAINS(record.Description, "example")';
334+
FormulaFilter filter = new FormulaFilter(
335+
configuration,
336+
TriggerOperation.BEFORE_UPDATE,
337+
ACCOUNT_SOBJECT_NAME
338+
);
339+
340+
FormulaFilter.Result result = filter.filterByEntryCriteria(
341+
triggerNew,
342+
triggerOld
343+
);
344+
345+
System.Assert.areEqual(
346+
1,
347+
result.triggerNew.size(),
348+
'Only 1 record should be processed when CONTAINS evaluates to null for the first record'
349+
);
350+
System.Assert.areEqual(
351+
1,
352+
result.triggerOld.size(),
353+
'Only 1 record should be processed when CONTAINS evaluates to null for the first record'
354+
);
355+
}
356+
330357
@SuppressWarnings('PMD.ApexDoc')
331358
global class AccountTriggerRecord extends TriggerRecord {
332359
global Account record {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
@SuppressWarnings('PMD.ApexDoc, PMD.ApexUnitTestClassShouldHaveRunAs')
18-
@IsTest
18+
@IsTest(IsParallel=true)
1919
private class TriggerActionFlowAddErrorTest {
2020
private static final String MY_STRING = 'MY_STRING';
2121
private static final String NAME = 'Name';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
@SuppressWarnings('PMD.ApexDoc, PMD.ApexUnitTestClassShouldHaveRunAs')
18-
@IsTest
18+
@IsTest(IsParallel=true)
1919
private class TriggerActionFlowClearBypassTest {
2020
private static final String MY_STRING = 'MY_STRING';
2121
private static List<TriggerActionFlowClearBypass.Request> requests = new List<TriggerActionFlowClearBypass.Request>();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
@SuppressWarnings('PMD.ApexDoc, PMD.ApexUnitTestClassShouldHaveRunAs')
18-
@IsTest
18+
@IsTest(IsParallel=true)
1919
private class TriggerActionFlowIsBypassedTest {
2020
private static final String MY_STRING = 'MY_STRING';
2121
private static List<TriggerActionFlowIsBypassed.Request> requests = new List<TriggerActionFlowIsBypassed.Request>();

0 commit comments

Comments
 (0)