Newer Version Available

This content describes an older version of this product. View Latest

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 “Managing Apex Triggers” in the Salesforce online help. This metadata type extends the MetadataWithContent component and shares its fields.

Supported Calls

deploy(), retrieve(), describeMetadata(), listMetadata()

This metadata type is not supported by the create(), delete(), and update() calls.

Note

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:

Field Name Field Type Description
apiVersion double Required. The API version for this trigger. Every trigger has an API version specified at creation.
content base64 The Apex trigger definition. This field is inherited from the MetadataWithContent component.
fullName string The Apex trigger name. The name can only contain characters, letters, and the underscore (_) character, must start with a letter, and cannot end with an underscore or contain two consecutive underscore characters. This field is inherited from the Metadata component.
packageVersions PackageVersion[] The list of installed managed package versions that are referenced by this Apex trigger.

For more information about managed packages, see the Force.com Quick Reference for Developing Packages. For more information about package versions, see “About Package Versions” in the Salesforce online help. This field is available in API version 16.0 and later.

status ApexCodeUnitStatus (enumeration of type string) Required. The current status of the Apex trigger. The following string values are valid:
  • Active - The trigger is active.
  • Inactive - The trigger is inactive, but not deleted.
  • Deleted - The trigger is marked for deletion. This is useful for managed packages, because it allows a trigger to be deleted when a managed package is updated.

Declarative Metadata Sample Definition

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

MyHelloWorld.trigger file:

1trigger helloWorldAccountTrigger on Account (before insert) {
2
3  Account[] accs = Trigger.new;
4
5   MyHelloWorld.addHelloWorld(accs);
6}

MyHelloWorld.trigger-meta.xml:

1<?xml version="1.0" encoding="UTF-8"?>
2<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
3    <apiVersion>32.0</apiVersion>
4</ApexTrigger>