You are here:
Workflow for Using a Trigger and an On Creation Action
You can configure a trigger to perform initialization tasks when a new base object record is created. A common initialization task, available in Spring '20 and later releases, is to process an On Creation Action associated with the State Model Version. Other initialization tasks are possible. For example, a trigger for Application__c records sets the initial state of the associated State Model to the Submitted state.
Before You Begin
Before you can set up a trigger and an On Creation Action, you must prepare the base object and create the State Model, States, and State Transitions. You don't need the State Rules or other actions, because your State Model only needs to reach the initial state. However, you do need the ReportCardEmail class that other actions use.
To create the example On Creation Action, you must first perform these tasks at a minimum:
In the Report Card State Model example, an enrollment email is sent to the student when a new Report_Card__c object is created.
As an alternative to using an On Creation Action, you can create an action associated with the initial state. This doesn't require a trigger. See Workflow for Creating Actions for States and Rules.
- Create an EnableStateModel Trigger in Custom Settings.
- Create a Trigger for the Base Object.
- Create the Email Template for the On Creation Action.
- Create the Vlocity Action for the On Creation Action.
- Add the On Creation Action.
- Test the On Creation Action.
- Create an EnableStateModel Trigger in Custom Settings
To create an EnableStateModel trigger for the Report_Card__c object: - Create a Trigger for the Base Object
The ReportCard trigger ensures that the Report_Card.EnableStateModel setting exists and is set to On, then invokes the processOnCreateActions method. You can rewrite it to work with a different base object. - Create the Email Template for the On Creation Action
The On Creation Action uses its own Email Template. - Create the Vlocity Action for the On Creation Action
The Vlocity Action connects the trigger and the Email Template. - Add the On Creation Action
The On Creation Action connects the Vlocity Action to the Report Card State Model. - Test the On Creation Action
After you have created the On Creation Action, the final task is to test it.

