ApexTrigger

Represents the saved copy of an Apex trigger. ApexTrigger uses the cached version of the class unless one is unavailable. Available from API version 28.0 or later.

To edit, save, or compile Apex triggers, use ApexTriggerMember.

Supported SOAP API Calls

create()delete()describeSObjects()query()retrieve()update()upsert()

Supported REST API HTTP Methods

Query, GET, POST, PATCH, DELETE

Fields

Field Name Details
ApiVersion
Type
double
Properties
Create, Filter, Sort, Update
Description
The API version for this trigger. Every trigger has an API version specified at creation.
Body
Type
string
Properties
Create, Nillable, Update
Description
The Apex trigger definition. Limit: 1 million characters.
BodyCrc
Type
double
Properties
Create, Defaulted on create, Filter, Nillable, Sort, Update
Description
The CRC (cyclic redundancy check) of the class or trigger file.
EntityDefinitionId
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The Id of the EntityDefinition object associated with this object.
IsValid
Type
boolean
Properties
Create, Defaulted on create, Filter, Group, Sort, Update
Description
Indicates whether any dependent metadata has changed since the trigger was last compiled (true) or not (false).
LengthWithoutComments
Type
int
Properties
Create, Filter, Group, Sort, Update
Description
Length of the trigger without comments.
ManageableState
Type
ManageableState enumerated list
Properties
Filter, Group, Nillable, Restricted picklist, Sort
Description
Indicates the manageable state of the specified component that is contained in a package:
  • beta
  • deleted
  • deprecated
  • deprecatedEditable
  • installed
  • installedEditable
  • released
  • unmanaged
Metadata
Type
ApexTriggerMetadata
Properties
None
Description
An object that describes the version, status, and packaged versions of the corresponding Apex trigger.
Query this field only if the query result contains no more than one record. Otherwise, an error is returned. If more than one record exists, use multiple queries to retrieve the records. This limit protects performance.
Status
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The 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 status is useful for managed packages, because it allows a class to be deleted when a managed package is updated.

Apex triggers cannot be deactivated using Tooling API. You can deactivate Apex triggers using Metadata API. Consider using custom metadata records and include logic in your trigger to bypass trigger configuration logic. For more information, see the Metadata API Developer Guide.

Note

UsageAfterDelete
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an after delete trigger (true) or not (false).
UsageAfterInsert
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an after insert trigger (true) or not (false).
UsageAfterUndelete
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an after undelete trigger (true) or not (false).
UsageAfterUpdate
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an after update trigger (true) or not (false).
UsageBeforeDelete
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is a before delete trigger (true) or not (false).
UsageBeforeInsert
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an before insert trigger (true) or not (false).
UsageBeforeUpdate
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is an before update trigger (true) or not (false).
UsageIsBulk
Type
boolean
Properties
Create, Filter, Update
Description
Specifies whether the trigger is defined as a bulk trigger (true) or not (false).

Usage

To retrieve information about an Apex trigger, create an ApexTrigger object that references it. For example code, see SOAP Calls.

To edit, save, or compile Apex triggers, use ApexTriggerMember.

Although Apex classes and triggers have the Create and Update field properties, a runtime exception occurs if you try to create, update, or delete them using the API. Instead, use the Salesforce Extensions for Visual Studio Code or the Ant Migration Tool to create or update Apex classes or triggers. Apex classes and triggers can’t be created, edited, or deleted in a production org. See Deploying Apex.