Skip to content

UTIL_FormulaFilter

Class · Group: Utilities

apex
global inherited sharing class UTIL_FormulaFilter

Class that can filter list of SObject based on Formula Information provided adapted from:apex-trigger-actions-framework

Example

apex
UTIL_FormulaFilter filter = new UTIL_FormulaFilter(
    'MyProcess', 'UTIL_FormulaContext.AccountContext', 'newRecord.Industry == "Technology"'
);
UTIL_FormulaFilter.DTO_FilterResults results = filter.filter(oldRecords, newRecords);

Methods

MethodDescription
global UTIL_FormulaFilter.DTO_FilterResults filter(List<SObject> oldRecords, List<SObject> newRecords)Filters the given lists of new and old SObjects based on the entry criteria formula.

filter

apex
global UTIL_FormulaFilter.DTO_FilterResults filter(List<SObject> oldRecords, List<SObject> newRecords)

Filters the given lists of new and old SObjects based on the entry criteria formula.

This method evaluates the entry criteria formula for each record in the triggerNew and triggerOld. If the formula evaluates to true for a record, it is included in the filtered lists.

NOTE: Make sure that if both the old and new records lists are not null they are the same size

Parameters

ParameterTypeDescription
oldRecordsListThe list of old SObjects to filter.
newRecordsSObjectThe list of new SObjects to filter.

Returns UTIL_FormulaFilter.DTO_FilterResults — An object containing the filtered lists of new and old SObjects.

Throws

ExceptionDescription
ExceptionException could be thrown if the any of the formula build method's fail

Example

apex
DTO_FilterResults result = instance.filter(records, records);

Constructors

ConstructorDescription
global UTIL_FormulaFilter(String processName, String contextClassName, String formula)Constructs a new instance with the formula details

UTIL_FormulaFilter(String processName, String contextClassName, String formula)

apex
global UTIL_FormulaFilter(String processName, String contextClassName, String formula)

Constructs a new instance with the formula details

Parameters

ParameterTypeDescription
processNameStringThe name of the process calling the filter, will be used if an error is generated during process so logging will be specific
contextClassNameStringThe class that will provide the relevant variables, context to the formula.
formulaStringThe boolean formula to execute

Example

apex
UTIL_FormulaFilter instance = new UTIL_FormulaFilter('value', 'value', 'RecordType.Name = \'Default\'');

Inner Classes

ClassDescription
DTO_FilterResultsInner class representing the result of the filter method.
INT_SObjectFormulaEvaluationContextInterface for providing context data to dynamic formula evaluations using Salesforce's FormulaEval namespace.