Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry Criteria in Trigger Action Metadata #135

Closed
mitchspano opened this issue Jan 13, 2024 · 3 comments · Fixed by #159
Closed

Entry Criteria in Trigger Action Metadata #135

mitchspano opened this issue Jan 13, 2024 · 3 comments · Fixed by #159
Labels
enhancement New feature or request

Comments

@mitchspano
Copy link
Owner

With the introduction of the FormulaEval namespace (available in developer preview for Spring 24 release), Salesforce will enable us to define formulas as strings and dynamically express values with these formulas.

The Trigger Actions metadata within the framework should support these formulas to define an optional entry criteria for the actions.

global class TriggerActionRecord {
  global SObject record; // new version of the record in the DML operation
  gloabl SObject recordPrior; // old version of the record in the DML operation
}

For example, if we wanted a trigger action to execute only if the Description has been changed and now contains the string "Now take action", then we would define the entry criteria as such:
Trigger_Action__mdt.Entry_Criteria__c

CONTAINS(record.Description, "Now take action") && (record.Description <> recordPrior.Description)

When the DML operation occurs, the system will create instances of TriggerActionRecord from the contents of Trigger.new and Trigger.old, then check them against the criteria formula.

If the formula evaluates to true, then the records will be filtered into the newList and oldList which will be passed into the Trigger Action class.

If no records evaluate to true, there will be no dynamic instantiation of the trigger action.

@mitchspano mitchspano added the enhancement New feature or request label Jan 13, 2024
@jefersonchaves
Copy link

Yes, I had a similar thought, so seeing it being considered is nice.

Question: what would be the benefit of adding an Entry Criteria on metadata vs a Short-Circuit condition at the start of the trigger handler method?

@mitchspano
Copy link
Owner Author

The main advantage would be visibility of entry criteria from the metadata record itself without having to open the apex class.
The second benefit would be to help with the trigger action flow recursion depth issue that is explained here:

https://github.com/mitchspano/apex-trigger-actions-framework?tab=readme-ov-file#define-a-flow

@dschibster
Copy link
Contributor

This would also enable us to execute certain actions only for select Record Types, which I would greatly appreciate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants