140 likes | 165 Views
Trigger support provided by Apex for management of records, as is there in the database system support triggers. Get Certification in Salesforce and become an expert.
E N D
Essentials to Become an Expert in Salesforce Apex Triggers
Introduction Triggers are scripts in Apex that get executed either before or post the happening of specific DML (data manipulation language) events.
objective • Introduction • Key Points of Triggers • Trigger Syntax Code • Events in Trigger Syntax • Types of Triggers • Key Consideration • Trigger Exceptions • Bulk Triggers • Context Variables • Conclusion
Key Points of Triggers • Many actions like insertions, deletions, etc. can be performed to the Salesforce records • There in the database system support triggers • Triggers are employed in performing those operations that are backed by certain conditions like for modification of some linked records or even preventing some operations from taking place. • Triggers are thus used for almost anything in Apex which also includes execution of SOQL and DML. • Triggers can also be employed for the performance of those tasks which cannot be undertaken by making use of the point-and-click tools in the Salesforce user interface.
Events in Trigger Syntax • Before insert • Before update • Before delete • After insert • After update • After delete • After undelete
Types of Triggers • After Triggers: They are used for accessing the field values which are earmarked by the system. It is also useful in affecting changes in other records. Every record which actually fires the after the trigger is a read-only record. Before Triggers: They are basically used for both the validation and update of various values before they have been saved in the database.
Key Consideration • Upsert triggers are used for firing triggers both prior to the insert and even post the insert. It can also fire before or after the update triggers, whichever scenario fits better. • Mergetriggers, likewise are used for firing both before and after the delete for the records which are losing. It can also fire for both prior to and post the update triggers for the records which are winning. • It has been seen that the triggers that are executed post records are not deleted only end up working with certain particular objects. • There is no recording of the field history till the trigger ends. • The tracking of field history is subject to the permissions of the user, and if the latter does not have the suitable permissions but ends up in activating the trigger which makes some change to the object or field which has tracking enabled for history, no changes will be made in the history. • All kinds of callouts have to be made asynchronously from a trigger so as not to block the trigger process until there is no response for the external service.
Trigger Exceptions • Triggers are also used for the prevention of DML operations from taking place by calling on the addError() method either on a record or a field. • New Records in both the insert and update triggers, and also on Trigger. • Old Records in delete triggers, the custom error message shows up on the interface of the application, and it is also logged.
Bulk Triggers Bulk triggers are helpful in the handling of both solo record updates and other kinds of bulk operations, for instance: • Import of Data • Bulk API calls on the Lightning platform • Bulk or mass actions • Other kinds of recursive methods in Apex can call DML statements in bulk
Context Variables • isExecuting • isInsert • isUpdate • isDelete / isUndelete • isBefore / isAfter • new / old • newMap / oldMap • operationType • size
Conclusion • Knowledge of the basic aspects of the Apex triggers by taking some suitable training and certifications • So you are able to address the core issues in the same • JanBaskTraining has state of the art training modules which address all these core points along with many other vital aspects of Salesforce to prepare you for the future.
Thank You Happy Learning