ApexTrigger

Represents the saved copy of an Apex trigger. ApexTrigger uses the cached version of the class unless one is unavailable.

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

Version 

Introduced in API version 8.0.

Supported SOAP API Calls 

create(), delete(), describeSObjects(), getDeleted(), getUpdated(), query(), retrieve(), search(), update(), upsert()

Supported REST API Methods 

DELETE, GET, HEAD, PATCH, POST, Query

Fields 

ApiVersion 

  • Type: double

  • Required: No

  • Properties: Create, Filter, Sort, Update

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

Body 

  • Type: textarea

  • Required: No

  • Properties: Create, Nillable, Update

  • Description: The Apex trigger definition. Limit: 1 million characters.

BodyCrc 

  • Type: double

  • Required: No

  • Properties: Create, Defaulted on create, Filter, Nillable, Sort, Update

  • Description: The CRC (cyclic redundancy check) of the class or trigger file.

EntityDefinitionId 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Sort

  • Introduced: API version 33.0

  • Description: The Id of the EntityDefinition object associated with this object.

FullName 

  • Type: string

  • Required: No

  • Properties: Group, Nillable

  • Introduced: API version 31.0

  • Description: The internal name of the object. White spaces and special characters are escaped for validity. The name must:

  • Contain characters, letters, or the underscore (_) character

  • Must start with a letter

  • Can’t end with an underscore

  • Can’t contain two consecutive underscore characters.

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.

IsValid 

  • Type: boolean

  • Required: No

  • 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).

  • Default value: false

LengthWithoutComments 

  • Type: int

  • Required: No

  • Properties: Create, Filter, Group, Sort, Update

  • Description: Length of the trigger without comments.

ManageableState 

  • Type: picklist

  • Required: No

  • Properties: Filter, Group, Nillable, Restricted picklist, Sort

  • Introduced: API version 35.0

  • Description: Indicates the manageable state of the specified component that is contained in a package:

  • beta

  • deleted

  • deprecated

  • deprecatedEditable

  • installed

  • installedEditable

  • released

  • unmanaged

  • Possible values:

    • beta — beta

    • deleted — deleted

    • deprecated — deprecated

    • deprecatedEditable — deprecatedEditable

    • installed — installed

    • installedEditable — installedEditable

    • released — released

    • unmanaged — unmanaged

Metadata 

  • Type: complexvalue

  • Required: No

  • Properties: Create, Nillable, Update

  • Introduced: API version 31.0

  • 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.

Name 

  • Type: string
  • Required: No
  • Properties: Create, Filter, Group, idLookup, Sort, Update

NamespacePrefix 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The namespace prefix associated with this object. Each Developer Edition organization that creates a managed package has a unique namespace prefix. Limit: 15 characters. You can refer to a component in a managed package by using the namespacePrefix__componentName notation.

The namespace prefix can have one of the following values:

  • In Developer Edition organizations, the namespace prefix is set to the namespace prefix of the organization for all objects that support it. There is an exception if an object is in an installed managed package. In that case, the object has the namespace prefix of the installed managed package. This field’s value is the namespace prefix of the Developer Edition organization of the package developer.
  • In organizations that are not Developer Edition organizations, NamespacePrefix is only set for objects that are part of an installed managed package. There is no namespace prefix for all other objects.

Status 

  • Type: picklist

  • Required: No

  • Properties: Create, Filter, Group, Restricted picklist, Sort, Update

  • Introduced: API version 13.0

  • Description: The status of the Apex trigger. The following string values are valid:

  • Possible values:

    • Inactive — Inactive — The trigger is inactive, but not deleted.

    • Active — Active — The trigger is active.

    • 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

TableEnumOrId 

  • Type: picklist
  • Required: No
  • Properties: Create, Filter, Group, Nillable, Restricted picklist, Sort, Update

UsageAfterDelete 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an after delete trigger (true) or not (false).

UsageAfterInsert 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an after insert trigger (true) or not (false).

UsageAfterUndelete 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an after undelete trigger (true) or not (false).

UsageAfterUpdate 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an after update trigger (true) or not (false).

UsageBeforeDelete 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is a before delete trigger (true) or not (false).

UsageBeforeInsert 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an before insert trigger (true) or not (false).

UsageBeforeUpdate 

  • Type: boolean

  • Required: No

  • Properties: Create, Filter, Update

  • Description: Specifies whether the trigger is an before update trigger (true) or not (false).

UsageIsBulk 

  • Type: boolean

  • Required: No

  • 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 .

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.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!