Newer Version Available
ApexTrigger
For more information, see “Manage Apex Triggers” in Salesforce Help. This type extends the MetadataWithContent metadata type and inherits its content and fullName fields.
Supported Calls
All Metadata API calls except CRUD-Based Calls, 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:
| 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 can’t 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 Second-Generation Managed Packaging Developer Guide. This field is available in API version 16.0 and later. |
| status | ApexCodeUnitStatus (enumeration of type string) | Required. The status of the Apex trigger. The following string values are valid:
|
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>66.0</apiVersion>
4</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.