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

Since: 1.0

Example:

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

Properties

PropertyDescription
global interface INT_SObjectFormulaEvaluationContextInterface for providing context data to dynamic formula evaluations using Salesforce's FormulaEval namespace.

Methods

MethodDescription
global UTIL_FormulaFilter.DTO_FilterResults filter(List<List<SObject> newRecords)Filters the given lists of new and old SObjects based on the entry criteria formula.
global UTIL_FormulaFilter(String processName, String contextClassName, String formula)Constructs a new instance with the formula details

Inner Classes

ClassDescription
DTO_FilterResultsInner class representing the result of the filter method.

Method Details

UTIL_FormulaFilter

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

Constructs a new instance with the formula details

Parameters:

  • processName (String) - The name of the process calling the filter, will be used if an error is generated during process so logging will be specific
  • contextClassName (String) - The class that will provide the relevant variables, context to the formula.
  • formula (String) - The boolean formula to execute

Since: 1.0

Example:

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

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:

  • oldRecords (List) - The list of old SObjects to filter.
  • newRecords (SObject) - The list of new SObjects to filter.

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

Throws:

  • Exception - Exception could be thrown if the any of the formula build method's fail

Since: 1.0

Example:

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