What is Apex Triggers.? Why we Use? What is Syntex? What is Events? What is Context Variable? What is bulkify triggers?
➡️ Apex Triggers:-
-> This is automation tool. Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.
-> It executes before or after the following types of operations:
- Insert
- Update
- Delete
- Upsert
- Undelete
- Merge
➡️ Why we use Apex Triggers?
-> When we are not abel to solve some complex requirements throuth Salesforce Point and Click tools (Flows, PB, WF) then we can use apex triggers.
➡️ Types of Apex Triggers:-
=> There are two types of triggers.
-> Before triggers are used to update or validate record values before they’re saved to the database.
-> After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field), and to affect changes in other records. The records that fire the after trigger are read-only.
➡️ Apex Triggers Events:-
=> There are 7 types of events.
- Before Insert
- Before Update
- Before Delete
- ------------------
- After Insert
- After Update
- After Delete
- After Undelete
➡️ Apex Triggers Context Variables:-
=> There are following type of context variables in trigger
- Trigger.new Returns a list of the new versions of the sObject records. This sObject list is only available in Insert , update, and undelete triggers, and the records can only be modified in Before triggers.
- Trigger.old Returns a list of the old versions of the sObject records. This sObject list is only available in update and delete triggers.
- Trigger.isInsert Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API.
- Trigger.isUpdate Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or the API.
- Trigger.isDelete Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or the API.
- Trigger.isBefore Returns true if this trigger was fired before any record was saved.
- Trigger.isAfter Returns true if this trigger was fired after all records were saved.
- Trigger.isUndelete Returns true if this trigger was fired after a record is recovered from the Recycle Bin. This recovery can occur after an undelete operation from the Salesforce user interface, Apex, or the API.
- Trigger.newMap A map of IDs to the new versions of the sObject records This map is only available in before update, after insert, after update, and after undelete triggers.
- Trigger.oldMap A map of IDs to the old versions of the sObject records. This map is only available in
- Trigger.size The total number of records in a trigger invocation, both old and new.
- Trigger.isExecuting Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call.
➡️ What is Bulkify Apex Triggers?
-> Bulk triggers can handle both single record updates and bulk operations like: Data import. Lightning Platform Bulk API calls. Mass actions, such as record owner changes and deletes.
➡️ Apex Triggers Syntex:-
trigger TriggerName on ObjectName (trigger_events1,trigger_events2) {
//your code blocks..
}
Comments
Post a Comment