Salesforce Triggers are pieces of Apex code that run before or after changes to Salesforce records, like insertions, updates, or deletions. They help automate tasks and enforce business logic without manual intervention. Triggers are a vital part of backend development in Salesforce and often come up in technical interviews. If you are aiming for a Salesforce developer role, having a strong grasp of triggers is essential. In this blog, we have listed the top 15+ Salesforce interview questions on triggers to help you prepare effectively.
Fun Fact – Triggers are among the most commonly tested topics in Salesforce developer interviews.
Salesforce Interview Questions on Triggers for Freshers
Here are some of the most commonly asked interview questions on triggers in Salesforce for freshers.
- What is a trigger in Salesforce and when would you use one instead of a workflow rule?
A trigger is Apex code that runs before or after database events like insert, update, or delete. I would use a trigger when logic can’t be handled by workflow rules or flows – for example, when I need to update unrelated objects or handle multiple records at once.
- What are the different types of triggers in Salesforce?
There are two types: before and after triggers. Before triggers run before data is saved, useful for validations or updates. After triggers run after the data is saved, ideal for working with related records.
- What is the difference between “before” and “after” triggers?
Before triggers let you change values before saving. After triggers are used when you need record IDs or need to update related objects. You can’t modify the same record in after triggers.
- Can you explain the trigger.new and trigger.old contexts with examples?
Yes. trigger.new holds the new values of records during insert or update. trigger.old stores the old values before an update or delete. For example, I can compare both to see if a field was changed.
- How do you avoid recursive trigger execution in Salesforce?
I create a static Boolean variable in a helper class. It tracks if the trigger has already run. This way, I can skip re-running logic during updates made inside the trigger itself.
Salesforce Interview Questions on Triggers for Experienced Professionals
These are some of the most frequently asked trigger in Salesforce interview questions for experienced professionals.
- How do you handle bulk data in triggers to avoid governor limits?
I use collections like maps and sets to handle records in bulk. I avoid writing queries or DML statements inside for-loops. Instead, I query all required data at once, perform logic, and then update or insert in a single operation.
- What is a trigger framework, and have you implemented one in your projects?
A trigger framework is a structured approach to keep trigger code clean and manageable. It separates logic into handler classes and supports bulk operations, recursion control, and trigger context handling. Yes, I have used frameworks like the “TriggerHandler” pattern to improve code reuse and maintenance.
- How do you write a trigger that works for both insert and update operations without duplicating logic?
I check the trigger context using Trigger.isInsert or Trigger.isUpdate and use a single method in a handler class to perform shared logic. This way, I avoid repeating code for each operation.
- When would you prefer a trigger over Process Builder or Flow in complex scenarios?
I choose a trigger when logic needs cross-object access without direct relationships or when performance is a concern. Triggers also give more control during bulk operations and allow handling before/after events which Flow can’t always manage effectively.
- How do you handle callouts from a trigger, given the restrictions?
Callouts aren’t allowed directly in triggers. So, I queue the request using a future method, Queueable Apex, or a platform event. This lets the callout happen asynchronously, without blocking the trigger execution or violating limits.
Scenario Based Salesforce Interview Questions on Triggers
These are some of the most common trigger scenario based interview questions in Salesforce that test problem-solving skills.
- A user updates a Contact’s email – how would you update the related Case records automatically?
Write an after update trigger on Contact. Collect updated Contact IDs and their new emails. Use a SOQL query to fetch related Cases. Update a custom field on Case, like Contact_Email__c, with the latest email. Store all updates in a list and perform a bulk update at the end to keep it efficient.
- How would you prevent deleting an Account if it has related Contacts?
Use a before delete trigger on Account. Query Contacts where AccountId matches. If any are found, use addError() to stop the deletion.
- You want to update a field on a parent object based on changes in its child records. How would you handle this in a trigger?
I would write an after insert, update, or delete trigger on the child object. Then I would use a map to track parent IDs, perform an aggregate query (like COUNT or SUM), and update the parent field accordingly. All logic would be bulk-safe.
Coding Interview Questions on Triggers in Salesforce
Here are the commonly asked Salesforce trigger coding interview questions to help you practice real-time logic and Apex skills.
- Write a trigger that prevents insertion of duplicate Contacts based on email address.
trigger PreventDuplicateContact on Contact (before insert) {
Set<String> emails = new Set<String>();
for (Contact c : Trigger.new) {
if (c.Email != null) emails.add(c.Email.toLowerCase());
}
Map<String, Contact> existingContacts = new Map<String, Contact>();
for (Contact c : [SELECT Email FROM Contact WHERE Email IN :emails]) {
existingContacts.put(c.Email.toLowerCase(), c);
}
for (Contact c : Trigger.new) {
if (c.Email != null && existingContacts.containsKey(c.Email.toLowerCase())) {
c.addError(‘A contact with this email already exists.’);
}
}
}
- Write a trigger to update the “Last_Contacted__c” field on Account when a related Contact is updated.
trigger UpdateLastContacted on Contact (after update) {
Set<Id> accountIds = new Set<Id>();
for (Contact c : Trigger.new) {
if (c.AccountId != null) accountIds.add(c.AccountId);
}
List<Account> accToUpdate = new List<Account>();
for (Id accId : accountIds) {
accToUpdate.add(new Account(Id = accId, Last_Contacted__c = System.today()));
}
if (!accToUpdate.isEmpty()) update accToUpdate;
}
- Write a trigger that sets a custom status on a Lead when the Lead is updated.
trigger UpdateLeadStatus on Lead (before update) {
for (Lead l : Trigger.new) {
if (l.Status != ‘Qualified’) {
l.Status = ‘Working – Contacted’;
}
}
}
Tips to Prepare for Salesforce Interview Questions on Triggers
Here are some tips you can follow to prepare for Salesforce interview questions on triggers.
- Understand when to use before vs after triggers
- Practice writing bulk-safe code using collections
- Learn how to avoid recursion using static variables
- Build small trigger-based projects or exercises
- Review real-life scenarios and implement trigger solutions
- Follow naming conventions and keep code readable
Wrapping Up
These 15+ Salesforce interview questions on triggers cover key topics you are likely to face in real interviews. Practicing these will help you feel more confident and ready for trigger-based questions.
Want more Salesforce job opportunities? Visit Hirist – a top job portal built for tech professionals looking for Salesforce developer and trigger-based roles.
FAQs
As per AmbitionBox, the average Salesforce developer salary in India ranges from ₹3.0 Lakhs to ₹14.0 Lakhs per year, depending on experience, location, and skillset.
Understand the concept clearly, explain with real examples, and highlight any trigger-based projects you have worked on if possible.
Yes, triggers are a core part of Apex development and often appear in both fresher and experienced-level interviews.
Use a developer org to write and test triggers. Try solving real-world scenarios and review code on GitHub or Trailhead projects.