Monday, October 28, 2019

WHAT IS APEX TRIGGER IN SALESFORCE?

Apex triggers are used to manage records in Salesforce. It enables us to perform operations before or after the event is completed. In the “before event” we generally perform validations to prevent wrong entry into the database. In the “after event” we perform operations such as creating or updating a related record. The trigger is a very powerful mechanism using which we can do operations such as executing SOQL, executing DML operations, calling apex class methods.

A trigger is Apex code that executes before or after the following types of operations:

insert
update
delete
merge
upsert
undelete

TRIGGER SYNTAX:

trigger triggerName on objectName (trigger events) {
   // Block of code
}


where "trigger events" can be a comma-separated list of one or more of the following events:

before insert
before update
before delete
after insert
after update
after delete
after undelete

Note:

1) upsert triggers fire both before and after insert or before and after update triggers as appropriate.
2) merge triggers fire both before and after delete for the losing records, and both before and after update triggers for the winning record.

No comments:

Post a Comment