---
schema_version: "1"
id: e8ab093f823b3dd86aa6804d69581f1420fd54630af15fc7d242b4a2f1da4076
title: Trigger Syntax
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_triggers_syntax.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_syntax.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: dd2a3c3b89002b36b1b605b94c1c981b711bc6c12375c389e222beba7398cb9c
---
# Trigger Syntax

To define a trigger, use the following syntax, where _TriggerName_, _ObjectName_, _trigger\_events_, and _code\_block_ are placeholder values:

trigger TriggerName on ObjectName (trigger\_events) {
                     code\_block
                     }

The trigger\_events placeholder 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:

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

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.

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_bulk.htm "Bulk Triggers")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm "Trigger Context Variables")