Apex Trigger

Divyansh
3 min readMar 10, 2022

--

1.What is database trigger?

A database tigger is the special set of operations that is run when specific actions occur within database.

Triggers are defined to run when changes occur in table’s data.

2. What is apex trigger?

An apex trigger is apex code that runs when an specific operation occurs in salesforce objects.

Apex tigger are defined to run when data in object records changes.

Apex support trigger before and after following events-

· Insert

· Update

· Delete

· Undelete

· Upsert

· Merge

3. Why do we need apex Trigger ?

· Triggers are extremely useful in automating business processes.

· Triggers can be used to implement complex validation.

· Triggers can also be useful to communicate with third party system when data changes in salesforce.

4. Trigger Events-

· Before insert

· After insert

· Before update

· After update

· Before delete

· After undelete

5. Validations and throwing errors-

Triggers can be use to prevent DML operations from occurring by calling addError() method on record or field.

6. Multiple trigger-

· The order of execution in this case is not guaranteed

All these triggers share same set of governor limits

7. Trigger Context variables-

· isInsert — Return true if the trigger was fire due to insert operation.

· isUpdate — Return true if the trigger was fire due to update operation.

· isDelete — Return true if trigger was fire due to delete operation.

· isUndelete — Return true if trigger was fire due to undelete operation.

· isBefore — Return true if trigger was fired before any record is saved.

· isAfter — Return true if trigger was fired after any record is saved.

Apex Trigger

1.What is database trigger?

A database tigger is the special set of operations that is run when specific actions occur within database.

Triggers are defined to run when changes occur in table’s data.

2. What is apex trigger?

An apex trigger is apex code that runs when an specific operation occurs in salesforce objects.

Apex tigger are defined to run when data in object records changes.

Apex support trigger before and after following events-

· Insert

· Update

· Delete

· Undelete

· Upsert

· Merge

3. Why do we need apex Trigger ?

· Triggers are extremely useful in automating business processes.

· Triggers can be used to implement complex validation.

· Triggers can also be useful to communicate with third party system when data changes in salesforce.

4. Trigger Events-

· Before insert

· After insert

· Before update

· After update

· Before delete

· After undelete

5. Validations and throwing errors-

Triggers can be use to prevent DML operations from occurring by calling addError() method on record or field.

6. Multiple trigger-

· The order of execution in this case is not guaranteed

All these triggers share same set of governor limits

7. Trigger Context variables-

· isInsert — Return true if the trigger was fire due to insert operation.

· isUpdate — Return true if the trigger was fire due to update operation.

· isDelete — Return true if trigger was fire due to delete operation.

· isUndelete — Return true if trigger was fire due to undelete operation.

· isBefore — Return true if trigger was fired before any record is saved.

· isAfter — Return true if trigger was fired after any record is saved.

--

--