0% found this document useful (0 votes)
24 views21 pages

Mastering Salesforce Triggers

Salesforce Interview questions on ttigger

Uploaded by

Arpan Ganguly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
24 views21 pages

Mastering Salesforce Triggers

Salesforce Interview questions on ttigger

Uploaded by

Arpan Ganguly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 21
LS | Sandeep Sharma [fj LT] Are you ready to ace your next Salesforce interview? Learn the top most asked questions on triggers! What is a Trigger in Salesforce? A trigger in Salesforce is an Apex code block that executes before or after specific data manipulation events, such as insert, update, delete, or undelete operations, on records of a Salesforce object. Triggers allow you to perform custom logic and automate processes based on changes to records in the Salesforce database. What are the two types of triggers in Salesforce? There are two types of triggers in Salesforce: Before Triggers: These triggers execute before the record is saved to the database. They are used to modify or validate the data before it's ekoeSTSINcIe After Triggers: These triggers execute after the record is saved to the database. They are used for actions that require data to be in the database before performing the logic. What is the use of a trigger class in Salesforce? A trigger class in Salesforce contains the logic that is executed when a trigger event occurs. It holds the code that processes the records affected by the trigger event, performing custom actions, validations, updates, or creating related igclole] gece What are different events available in Triggers? Different events available in triggers include: e Before Insert Before Update e Before Delete e After Insert e After Update e After Delete e After Undelete When should we use trigger or automation? Triggers should be used when complex or custom logic is required based on specific data changes. Automation tools like Workflow Rules, Process Builder, and Flow are suitable for simpler scenarios where point-and-click configuration suffices. What are the best practices and considerations for Triggers? 1. Keep triggers focused on a single concern. 2. Bulkify your code to handle multiple records efficiently. 3.Avoid using DML statements within loops to prevent governor limits. 4.Use custom settings or custom metadata types to store configuration data. 5.Follow naming conventions and use comments for clarity. 6. Consider using trigger frameworks to improve code maintainability. How many times does a trigger execute on an Upsert event? A trigger executes once for each batch of records in an upsert operation. For example, if you're upserting 200 records, the trigger will execute once for the entire batch, not individually for each record. How many times does a trigger execute on a Merge event? A trigger only executes once for a merge event, even if multiple records are being merged. What is the order of execution for a Trigger? The order of execution for a trigger is as follows: 1.Before Triggers (order by object and order within object) 2.System Validation Rules 3.Duplicate Rules 4.After Triggers (order by object and order within object) 5.Assignment Rules 6.Auto-Response Rules 7.Workflow Rules 8.Processes 9.Escalation Rules 10.Roll-up Summary Fields 11.Post-Commit Logic (e.g., sending email) When will you choose before the event, and when will you choose after the event? e Use "Before" triggers when you need to validate or modify data before it's saved to the database. e Use "After" triggers when you need to perform actions that require data to be already saved to the database, like sending emails or creating related records. What is the difference between Trigger.New and Trigger.newMap? e Trigger.New is a list of the new versions of sObject records that were inserted or updated. e Trigger.newMap is a map of sObject IDs to their corresponding sObject records, useful for quickly accessing specific records in the trigger context. When should we use Trigger.Old? Trigger.Old provides the old versions of the sObject records before they were updated or deleted. It is used to compare changes and perform actions based on the previous state of the records. How to avoid recursion in Triggers? Use a static variable to track whether the trigger has already run in the current context. By setting the variable's value at the start and checking it before execution, you can prevent unwanted recursion. How to make acallout froma Bat =f:{-1 0rd Making a callout from a trigger directly is not recommended due to limitations and potential performance issues. Instead, use the @future annotation to make an asynchronous callout from a _ separate method or use the Queueable interface for more advanced scenarios. Can we calla batch job froma Bat =f:{-1 0rd Calling a batch job directly from a trigger is not allowed. However, you can initiate a batch job through other means, such as a Schedule job, future method, or Queueable job. What is the Trigger Handler pattern? The Trigger Handler pattern is an architectural approach to manage and organize trigger logic in a _ structured manner. It involves creating separate classes to handle different trigger events, making the code more modular, readable, and maintainable. Have you used any trigger framework in Salesforce? A trigger framework is a set of classes and methods that help organize and streamline trigger development. Examples include the Trigger Factory pattern or third-party frameworks like the "Apex Trigger Framework" by Kevin O'Hara. What is the difference between Validation rules and Triggers? e Validation Rules: These are point-and-click configuration settings that enforce data quality and integrity by setting conditions that must be met before records are saved. They are declarative and are primarily used to prevent bad data from Tal ncTaayem maT eoNec1e- 10a Triggers: These are pieces of Apex code that allow for more complex and customized data manipulation and automation. Triggers are used to perform custom actions, calculations, or updates based on specific data events. Remember that these answers provide a comprehensive overview of each question. In an interview, you may be asked to provide more specific examples or discuss practical scenarios related to these concepts. Follow a Sandeep Sharma For more. re

You might also like