Defining an Object-Level Trigger to Complement Default Processing
Triggers are scripts that you can write to complement the default processing logic for a standard or custom object. You can define triggers both at the object-level and the field-level.
The object-level triggers that are available are described below. See Defining a Field-Level Trigger to React to Value Changes for the available field-level triggers.
-
After Create :
Fires when a new instance of an object is created. Use to assign programmatic default values to one or more fields in the object.
-
Before Invalidate
Fires on a valid parent object when a child row is created, removed, or modified, or also when the first persistent field is changed in an unmodified row.
-
Before Remove
Fires when an attempt is made to delete an object. Returning false stops the row from being deleted and displays the optional trigger error message.
-
Before Insert in Database
Fires before a new object is inserted into the database.
-
Before Update in Database
Fires before an existing object is modified in the database
-
Before Delete in Database
Fires before an existing object is deleted from the database
-
After Changes Posted to Database
Fires after all changes have been posted to the database, but before they are permanently committed. Can be used to make additional changes that will be saved as part of the current transaction.
-
Before Commit in Database
Fires before the change pending for the current object (insert, update, delete) is made permanent in the current transaction. Any changes made in this trigger will not be part of the current transaction. Use "After Changed Posted to Database" trigger if your trigger needs to make changes.
-
Before Rollback in Database
Fires before the change pending for the current object (insert, update, delete) is rolled back
-
After Rollback in Database
Fires after the change pending for the current object (insert, update, delete) is rolled back
For example, consider a Contact
object with a
OpenTroubleTickets
field that needs to be updated any time a
trouble ticket is created or modified. You can create the following trigger on the
TroubleTicket
object that invokes the
updateOpenTroubleTicketCount()
object function described above.
-
Trigger Object:
TroubleTicket
-
Trigger: After Changes Posted to Database
-
Trigger Name:
After_Changes_Set_Open_Trouble_Tickets
Trigger Definition
adf.util.logStart('After_Changes_Set_Open_Trouble_Tickets')
// Get the related contact for this trouble ticket
def relatedContact = Contact_Obj_c
// Update its OpenTroubleTickets field value
relatedContact?.updateOpenTroubleTicketCount()