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.

Parent Type 

This type extends MetadataWithContent and inherits its fields.

Fields 

apiVersion 

  • Type: double
  • Required: Yes
  • Description: Required. The API version for this trigger. Every trigger has an API version specified at creation.

content 

  • Type: base64Binary
  • Required: No
  • Description: The Apex trigger definition. This field is inherited from the MetadataWithContent component.

fullName 

  • Type: string
  • Required: No
  • Description: 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 

status 

  • Type: ApexCodeUnitStatus (enumeration of type string)
  • Required: Yes
  • Description: Required. The status of the Apex trigger. The following string values are valid:
  • Possible values:
    • Active — The trigger is active.
    • Inactive — The trigger is inactive, but not deleted.
    • Deleted — The trigger is marked for deletion. 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>68.0</apiVersion>
4</ApexTrigger>

Supported Calls 

All Metadata API calls except CRUD-Based Calls, which prevents deployment outside of proper deployment lifecycle and test-execution constraints.

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.

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.