Newer Version Available
Associate Actions to Records with Apex
If you want to control how you trigger the creation of a RecordAction, you can use
Apex to associate actions to records. The RecordAction object is exposed as a standard
object in Apex. You can trigger it before a DML operation or on delete or undelete. You can
also provide custom error handling.
Here are some scenarios that Apex better accommodates.
- Triggering before a DML operation rather than after
- Triggering on delete and undelete DML operations
- Validating data before the action is run
- Custom error handling
- Partial completion rather than complete failure
Example
This example uses an Apex class and trigger pair to associate a flow to a newly created account that satisfies specific criteria. In the class, a method is defined that takes in a list of accounts and creates a RecordAction for each of them. It sets the new account as the RecordId and the ActionDefinition as an active flow. The trigger is called after the insert of an account record. When the criterion (type is Customer) is satisfied, the class method is executed, and it adds the defined flow to the new account.
Apex Class
Apex Trigger