Newer Version Available
Create an Apex Trigger
Use Apex triggers to perform custom actions before or after a change to a Salesforce
record, such as an insertion, update, or deletion. You can create Apex triggers from the CLI.
- If the triggers directory doesn’t exist in <app-dir>/main/default, create it.
-
Generate skeleton trigger files by executing force:apex:trigger:create.
- Use the -s parameter to specify the sObject associated with this trigger, such as Account.
- Use the -e parameter to specify the triggering events, such as before delete or after insert.
- Specify that the command generate its output into the triggers directory with the -d parameter.
The command generates two files.
- mytrigger.trigger-meta.xml—metadata format
- mytrigger.trigger—Apex source file
- Update the generated Apex and metadata format file with your code.