---
schema_version: "1"
id: deecd0b98da0ce891795cca4601b0a2ac2a2cf8c56d631dec5e976ec16b28b35
title: ApexTrigger
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_triggers.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_triggers.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 163346bf36235082d6c89dba57946fe09cbe97863598e372b0d892257c3b4e9d
description: Represents an Apex trigger. A trigger is Apex code that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.
---
# ApexTrigger

Represents an Apex trigger. A trigger is Apex code that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.

For more information, see “Manage Apex Triggers” in Salesforce Help. This type extends the [MetadataWithContent](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_metadatawithcontent.htm "MetadataWithContent is the base type for all metadata types that contain content, such as documents or email templates. It extends Metadata. You can’t edit this object.") metadata type and inherits its content and fullName fields.

## Supported Calls

All Metadata API calls except [CRUD-Based Calls](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_crud_based_calls_intro.htm "Use CRUD-based calls to work with metadata components in a manner similar to how synchronous API calls in the enterprise WSDL act upon objects."), which prevents deployment outside of proper deployment lifecycle and test-execution constraints.

## Declarative Metadata File Suffix and Directory Location

The file suffix is .trigger for the trigger file. The accompanying metadata file is named TriggerName\-meta.xml.

Apex triggers are stored in the triggers folder in the corresponding package directory.

## Version

Triggers are available in API version 10.0 and later.

## Fields

This metadata type contains the following fields:

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d926032e129">Field Name</th>

              <th class="featureTableHeader  " id="d926032e132">Field Type</th>

              <th class="featureTableHeader  " id="d926032e135">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d926032e129" data-title="Field Name"><span class="keyword parmname" id="api_version"><a name="api_version"><!-- --></a>apiVersion</span></td>

              <td class="entry" headers="d926032e132" data-title="Field Type">double</td>

              <td class="entry" headers="d926032e135" data-title="Description">Required. <span class="ph" id="trigger_apiversion_desc"><a name="trigger_apiversion_desc"><!-- --></a>The API version for this trigger.
                  Every trigger has an API version specified at creation.</span>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d926032e129" data-title="Field Name"><span class="keyword parmname">content</span></td>

              <td class="entry" headers="d926032e132" data-title="Field Type">base64</td>

              <td class="entry" headers="d926032e135" data-title="Description">The Apex trigger definition. This field is inherited from the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_metadatawithcontent.htm" title="MetadataWithContent is the base type for all metadata types that contain content, such as documents or email templates. It extends Metadata. You can’t edit this object.">MetadataWithContent</a>
                component.</td>

            </tr>

            <tr>
              <td class="entry" headers="d926032e129" data-title="Field Name"><span class="keyword parmname">fullName</span></td>

              <td class="entry" headers="d926032e132" data-title="Field Type">string</td>

              <td class="entry" headers="d926032e135" data-title="Description">The Apex trigger name. <span class="ph" id="fullName_allowed_chars"><a name="fullName_allowed_chars"><!-- --></a>The name can only
                  contain characters, letters, and the underscore (_) character, must start with a
                  letter, and can’t end with an underscore or contain two consecutive underscore
                  characters.</span> This field is inherited from the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/metadata.htm" title="The base class for all metadata types. You can’t edit this object. A component is an instance of a metadata type.">Metadata</a> component.</td>

            </tr>

            <tr>
              <td class="entry" headers="d926032e129" data-title="Field Name"><span class="keyword parmname" id="field_packageVersions"><a name="field_packageVersions"><!-- --></a>packageVersions</span></td>

              <td class="entry" headers="d926032e132" data-title="Field Type">
                <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_classes.htm#PackageVersion">PackageVersion</a>[]
              </td>

              <td class="entry" headers="d926032e135" data-title="Description">
                <span class="ph" id="field_packageVersions_desc"><a name="field_packageVersions_desc"><!-- --></a>The list of installed managed package
                  versions that are referenced by this Apex trigger.</span>
                <p class="p">For more information
                  about managed packages, see the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.pkg2_dev.meta/pkg2_dev/sfdx_dev_dev2gp.htm" target="_blank" title="PDF (New Window)">Second-Generation Managed
                    Packaging Developer Guide</a>. This field is available in API version 16.0
                  and later.</p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d926032e129" data-title="Field Name"><span class="keyword parmname">status</span></td>

              <td class="entry" headers="d926032e132" data-title="Field Type">ApexCodeUnitStatus (<a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_objects_intro.htm#enumeration_title">enumeration</a> of type
                string)</td>

              <td class="entry" headers="d926032e135" data-title="Description">Required. The status of the Apex trigger. The following string values are valid:<ul class="ul bulletList">
                  <li class="li">
                    <samp class="codeph nolang">Active</samp> - The trigger is active.
                  </li>

                  <li class="li">
                    <samp class="codeph nolang">Inactive</samp> - The trigger is inactive, but
                    not deleted.
                  </li>

                  <li class="li">
                    <samp class="codeph nolang">Deleted</samp> - The trigger is marked for
                    deletion. Useful for managed packages, because it allows a trigger to be deleted
                    when a managed package is updated.
                  </li>

                </ul>
              </td>

            </tr>

          </tbody>

        </table>

## Declarative Metadata Sample Definition

The following sample creates the MyhelloWorld.trigger trigger, and the corresponding MyHelloWorld.trigger-meta.xml metadata file.

MyHelloWorld.trigger file:

trigger helloWorldAccountTrigger on Account (before insert) {

  Account\[\] accs = Trigger.new;

   MyHelloWorld.addHelloWorld(accs);
}

MyHelloWorld.trigger-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion\>68.0</apiVersion\>
</ApexTrigger\>

## Wildcard Support in the Manifest File

This metadata type supports the wildcard character \* (asterisk) in the package.xml manifest file. For information about using the manifest file, see [Deploying and Retrieving Metadata with the Zip File](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/file_based_zip_file.htm).

#### See Also

- [ApexClass](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_classes.htm "Represents an Apex class. An Apex class is a template or blueprint from which Apex objects are created. Classes consist of other classes, user-defined methods, variables, exception types, and static initialization code.")