Salesforce Interview Questions on Triggers
A trigger is the piece of code, that is executed Before or After a record is inserted or updated.
Usually, an APEX (code) based evaluation of criteria to set off a chain of events.These events execute the following types of operations like : Insert, Update, Delete, Merge, Upsert and Undelete.
Hey Guys, In this post I am going to share Salesforce Interview Questions on Triggers
The trigger is defined as an Apex code that execute before or after the following functions such as insert, update and delete etc. Trigger enables to perform custom actions before and after modifications to the records of Salesforce.
There are two types of triggers:
• Before trigger are used to update or validate values of a record before they are saved to the database.
• After trigger are used to access field values of the records that are stored in the database and use these values to make changes in other records.
The records that fire the after trigger are read only.
trigger TriggerName on ObjectName (trigger_events) {
// Implement the Logic here code_block }
trigger myAccountTrigger on Account (before insert, before update) {
CreateAccount.getAccount(); }
1. myAccountTrigger – triggerName ( It is the name you would want to give your trigger).
2. Account – Objectname (It is the object on which the action needs to be performed).
3. before insert, before update – Trigger_events
Before insert: When using this event, the code block gets executed before a new record is inserted.
Before update: When you use this event, the code will get executed before a new record is updated in the object.
2. What are the various event on which a trigger can fire?
A trigger is a set of statement which can be executed on the following events. In above trigger events one or more of below events can be used with comma separated.
• before insert
• before update
• before delete
• after insert
• after update
• after delete
• after undelete
3. What are the considerations while implementing the Triggers?
Consider the following before implementing the triggers.
• Upsert trigger fires on 4 different events :- before(insert, update), after (insert, update)
• Merge trigger are fired on both events on delete
• Field history is updated after the trigger has successfully finished processing data.
• Any callout should be asynchronous so that trigger does not have to wait for the response.
• A trigger cannot have a static keyword in its code.
• If a trigger completes successfully the changes are committed to the database and if it fails the transaction is rolled back.
More information visit the link below:
https://learnfrenzy.com/blog/salesforce-interview-questions-on-triggers