Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Trigger Syntax

To define a trigger, use the following syntax:
1trigger TriggerName on ObjectName (trigger_events) {
2                     code_block
3                     }

where trigger_events can be a comma-separated list of one or more of the following events:

For example, the following code defines a trigger for the before insert and before update events on the Account object:

1trigger myAccountTrigger on Account (before insert, before update) {
2    // Your code here
3}

The code block of a trigger cannot contain the static keyword. Triggers can only contain keywords applicable to an inner class. In addition, you do not have to manually commit any database changes made by a trigger. If your Apex trigger completes successfully, any database changes are automatically committed. If your Apex trigger does not complete successfully, any changes made to the database are rolled back.