Apex Trigger Interview Questions are the heart of most Salesforce developer interviews. Triggers run code when records change, so interviewers test events, context variables, bulk safety and real scenarios. Expect at least one “write a trigger” task in every round.
Last reviewed for the Winter ’27 release (November 2026).
This is Part 10 of our Salesforce developer interview series. It covers trigger basics, context variables, before and after triggers and tricky cases, with short answers. It builds on Apex trigger basics and context variables, before vs after triggers and Part 9 on DML.
What are Apex Trigger Interview Questions?
Apex Trigger Interview Questions test how you write code that runs before or after records are saved. A trigger listens to events on one object, such as before insert or after update. Then it reads context variables, such as Trigger.new, to work on the records.
Think of a doorbell camera. It wakes up when someone arrives (insert), changes something (update) or leaves (delete). It can check visitors before they enter, or log them after they are inside.
Why Apex Trigger Interview Questions Matter
Triggers touch every save on an object, so one bad trigger can block a whole team. Here is why Apex Trigger Interview Questions matter.
- First, triggers must handle up to 200 records at a time.
- Also, choosing before or after decides whether you need DML at all.
- Next, context variables differ by event, which trips up many candidates.
- Recursion and limits cause most trigger failures in production.
- Finally, “trigger or flow?” is a standard design question.
So clear trigger answers show you can own real business logic.
How to Prepare for Apex Trigger Interview Questions
Preparing for Apex Trigger Interview Questions follows five steps. First, learn the seven trigger events. Next, memorise which context variables exist in each event. Then practise before triggers for field changes and after triggers for related records. After that, write every trigger for 200 records and test it. Finally, explain one real trigger you built and why it was not a flow.

Trigger Events at a Glance
The table below lists every trigger event and a typical use.
| Event | When it runs | Typical use |
|---|---|---|
| before insert | Before new records save | Set default values |
| before update | Before changes save | Validate or adjust fields |
| before delete | Before records are deleted | Block deletes |
| after insert | After new records save | Create related records |
| after update | After changes save | Update related records |
| after delete | After records are deleted | Clean up or log |
| after undelete | After records are restored | Restore related data |
Before vs After Triggers
The table below compares before and after triggers, the most asked question here.
| Feature | Before trigger | After trigger |
|---|---|---|
| Runs | Before the record saves | After the record saves |
| Change Trigger.new fields | Yes, no DML needed | No, read only |
| Record Id | Not set on insert | Set |
| Related records | Rarely | Create or update them |
| Typical use | Defaults and validation | Child records and other objects |
When to use which is simple. Use before triggers to change the same record, while after triggers fit when you need the Id or change other records.

Basic Apex Trigger Interview Questions
These Apex Trigger Interview Questions cover syntax, events and core rules.
Questions on Trigger Basics
Q1: What is an Apex trigger?
It is Apex code that runs before or after records are inserted, updated, deleted or undeleted. So it automates logic on save.
Follow-up you may get: Can a trigger run on more than one object? No, each trigger belongs to one object.
Q2: Write the basic trigger syntax.
trigger CourseTrigger on Course__c (before insert, after update) { }. Then list every event the trigger handles.
Interview tip: write the syntax from memory with two events. Written tests often start with this.
Q3: How many trigger events are there?
Seven: before insert, before update, before delete, after insert, after update, after delete and after undelete. There is no before undelete.
Interview tip: say “there is no before undelete”. It is the detail interviewers check.
Q4: How many records can a trigger receive at once?
Up to 200 records per chunk. So larger loads run the trigger several times in one transaction.
Follow-up you may get: What happens with a Bulk API batch of 10,000 rows? Salesforce splits it into chunks of 200 for the trigger, all within that batch’s transaction.
Q5: Do triggers run in system mode?
Yes, triggers run in system mode, so they ignore the user’s object and field access. However, record sharing can apply through classes they call.
Interview tip: add that the called class’s sharing keyword decides record access. Triggers alone do not enforce it.
Q6: Can you create a trigger directly in production?
No. You write it in a sandbox or scratch org and deploy it to production with tests.
Production does not allow creating or editing Apex triggers in Setup. The deployment runs your tests, and the trigger must have some coverage before it can go live.
Q7: What test coverage does a trigger need?
Each trigger needs at least 1% coverage, and the org needs 75% overall. In practice, aim for full bulk tests.
Q8: Can you turn a trigger off without deleting it?
Yes, set it to Inactive in a sandbox and deploy it. Also, many teams add a custom setting or metadata bypass.
Q9: Can a trigger call a class?
Yes, and it should. Keep the trigger to a line or two and move the logic into a handler class.
Example: trigger CourseTrigger on Course__c (before insert, after update) { new CourseTriggerHandler().run(); } The handler decides what to do for each event, and you can test it like any other class.
Q10: Can a trigger be written on a child object to update a master-detail parent?
Yes. Use an after trigger on the child, collect the parent IDs, query and change the parents, and update them in one DML. Before you write it, check whether a roll up summary field already does the job without code.
Q11: Which operations do not fire triggers?
Some system actions, such as cascade deletes of child records and mass campaign status changes. So do not rely on triggers for those.
Questions on Context Variables
Context-variable Apex Trigger Interview Questions are the most common, so learn the matrix below.

Q12: What is Trigger.new?
A List of the new versions of the records. It is available in insert, update and undelete triggers.
Q13: What is Trigger.old?
A list of the old versions of the records. It is available in update and delete triggers.
It is null in insert triggers, because there were no old values. Here is where each context variable is available:
| Event | Trigger.new | Trigger.newMap | Trigger.old | Trigger.oldMap |
|---|---|---|---|---|
| before insert | Yes, editable | No | No | No |
| after insert | Yes, read only | Yes | No | No |
| before update | Yes, editable | Yes | Yes | Yes |
| after update | Yes, read only | Yes | Yes | Yes |
| before and after delete | No | No | Yes | Yes |
| after undelete | Yes | Yes | No | No |
Q14: What are Trigger.newMap and Trigger.oldMap?
Maps of Id to record for the new and old versions. However, newMap is not available in before insert, because records have no Id yet.
Follow-up you may get: Is Trigger.newMap available in after insert? Yes, because IDs exist by then.
Q15: Can you change Trigger.new in an after trigger?
No, Trigger.new is read only in after triggers. So you must query and update the records instead.
Interview tip: mention the error you get, “Record is read-only”. It shows real experience.
Q16: Can you change Trigger.old?
No. Trigger.old is always read only.
It shows the values from before the change, so it is for comparing, not editing. Example: if (rec.Status__c != Trigger.oldMap.get(rec.Id).Status__c) tells you the status changed.
Q17: What are isBefore, isAfter, isInsert and the other flags?
Booleans that tell you the current event. For example, Trigger.isBefore && Trigger.isInsert.
Q18: What is Trigger.operationType?
An enum, System.TriggerOperation, such as BEFORE_INSERT. So you can use a switch statement on it.
Follow-up you may get: Why use operationType? A switch on it is cleaner than chains of isBefore and isInsert checks.
Q19: What does Trigger.size return?
The total number of records in the current chunk. So it is the same for old and new lists.
Q20: What is Trigger.isExecuting?
It returns true when the code runs inside a trigger. So a shared class can check its context.
Q21: What is Trigger.isInsert used for when a trigger also handles update?
It tells you which event is running, so shared code can branch: in an insert there is no old value to compare. With Trigger.operationType you can use a switch instead, like switch on Trigger.operationType { when BEFORE_INSERT { … } }.
Q22: How do you detect a field change in an update trigger?
Compare Trigger.oldMap.get(rec.Id).Field__c with rec.Field__c. Then act only on changed records.
Intermediate Apex Trigger Interview Questions
These Apex Trigger Interview Questions cover bulk design, errors and special events.
Questions on Bulk Triggers
Q23: What does bulkifying a trigger mean?
It means writing code that works for 1 or 200 records with the same number of queries and DML. So no SOQL or DML goes inside loops.
Follow-up you may get: Does bulkifying also mean bulk DML? Yes, one DML on a list after the loop.
Q24: Show the bulk pattern for reading parent data.
Collect parent Ids in a Set, query once into a Map, then loop the records. This uses one query for any chunk size.
Interview tip: write the Set, query and Map lines out loud. It is the answer most interviewers want.
Q25: How do you test a trigger for bulk safety?
Insert 200 records in one test with Test.startTest and Test.stopTest. Then assert results and limit usage.
Q26: What happens when Apex inserts 1,000 records in one DML statement?
The trigger runs five times with 200 records each, all in one transaction. So static variables carry over between chunks.
Interview tip: this explains why static Boolean guards are risky, so link the two ideas.
Q27: Can a trigger make a callout?
Not directly, because the record save must not wait on a remote server. Instead, call a future or Queueable method.
Q28: How do you avoid DML inside a trigger loop?
Add each record to a List inside the loop, then run one insert or update after the loop. For records of several types, collect them in a List<SObject> or use a Unit of Work.
Q29: How do you avoid hitting the 100 query limit in triggers?
Query once per chunk, reuse Maps and skip records that did not change. Also, keep queries out of helper loops.
Questions on Errors and Validation
Q30: How do you stop a save from a trigger?
Call addError on the record or a field, such as rec.Fee__c.addError(‘Too high’). So the user sees the message.
Follow-up you may get: Can addError take HTML? Yes, with addError(message, false) to stop escaping, but use it carefully.
Q31: Where can you call addError?
On records in Trigger.new for insert and update, and on Trigger.old for delete. So it blocks only those rows.
Q32: Does addError roll back the whole transaction?
For DML statements, yes, because they are all or none. However, with Database methods and allOrNone false, only that row fails.
Interview tip: this difference catches many people. Give both cases clearly.
Q33: Validation rule or trigger for validation?
Use a validation rule when a formula can express it. Use a trigger when you need queries or complex logic.
Q34: How do you show the same error on many records at once?
Loop through the failing records and call addError on each one. Each record gets its own message, and with partial success the good records still save.
Q35: How do you block deleting a course with active enrolments?
Use a before delete trigger, query enrolments for Trigger.oldMap.keySet() and call addError on matches. So the delete stops.
Follow-up you may get: Which variable do you use in before delete? Trigger.old or Trigger.oldMap.
Questions on Special Events
Q36: What happens in triggers during a merge?
Before and after delete fire for the losing records, and before and after update fire for the winner. Also, losers get MasterRecordId set in after delete.
Q37: Which variable is available in after undelete?
Trigger.new and Trigger.newMap.
They hold the restored records, so you can rebuild related data that was removed on delete, like a summary on the parent. Trigger.old is not available in undelete.
Q38: Does upsert fire insert or update triggers?
Both, depending on each record. New rows fire insert triggers, and matched rows fire update triggers.
Interview tip: say each row fires the matching event, so one upsert can fire both.
Q39: Do child triggers fire on a cascade delete from a master-detail parent?
No, deleting a parent does not fire delete triggers on the cascaded children. So handle cleanup on the parent trigger.
Q40: Do triggers fire during Bulk API and Data Loader loads?
Yes, they fire for API loads just like UI saves. So bulk loads are the best test of a trigger.
Q41: Can you write a trigger on a standard object such as Account?
Yes, triggers work on most standard and all custom objects. However, a few objects, such as some setup objects, do not support them.
Q42: Do triggers fire when a record is updated by a flow?
Yes. A flow that updates records runs normal DML, so the object’s triggers fire, along with validation rules and other flows. Keep this in mind when flows and triggers update the same records.
Q43: Can triggers run on platform events?
Yes, but only after insert, because events are published, not saved. Also, they run as the Automated Process user by default.
Advanced Apex Trigger Interview Questions
These Apex Trigger Interview Questions cover order, design and edge cases.
Questions on Trigger Order and Design
Q44: If an object has two triggers for the same event, which runs first?
The order is not guaranteed, so you cannot rely on it.
Salesforce may run them in any order, and the order can change between releases. That is why teams keep one trigger per object and control the order inside a handler.
Q45: Why is one trigger per object a best practice?
It gives a known order, one place to debug and easy bypass control. So logic stays predictable.
Interview tip: add that one trigger makes bypass switches simple. It shows operational thinking.
Q46: What is a trigger handler?
A class that holds the trigger logic, called from a thin trigger. For example, CourseTriggerHandler.run().
Follow-up you may get: Should the handler be with sharing? Usually inherited sharing or with sharing, decided per use case.
Q47: Trigger or record-triggered flow?
Use a record triggered flow for simple field updates and actions. Use a trigger for complex logic, high volume or code reuse.
| Point | Record triggered flow | Apex trigger |
|---|---|---|
| Who maintains it | Admins and developers | Developers |
| Simple field updates | Best choice, before save is very fast | Fine, but more effort |
| Complex logic and queries | Gets hard to read | Handles it well |
| Testing | Flow tests | Full unit tests with mocks |
| Order with other logic | Trigger Explorer and flow order settings | Controlled in the handler |
Q48: When do before-save flows run compared to before triggers?
Before-save flows run first, then before triggers. Also, after triggers run before after-save flows.
Q49: Do field updates in a before trigger fire the trigger again?
No, changes in Trigger.new save with the record without a new DML. So before triggers avoid recursion.
Q50: What is Trigger Explorer?
A Setup page that shows every trigger and record triggered flow on an object, grouped by event, in the order they run. It helps you find overlaps and decide the order of flows.
Q51: Why does an after update trigger often cause recursion?
It updates the same records with DML, which fires the update trigger again. So use a static guard or a before trigger.
Questions on Tricky Trigger Behaviour
Q52: What do Trigger.old values show after a workflow field update re-fires the trigger?
They show the values from before the original update, not the first update. So compare carefully on the second run.
Note: Workflow Rules and Process Builder support ended on 31 December 2025, so this mostly matters in older orgs. Flows that update the same record can cause a similar second run.
Q53: Are static variables reset between 200-record chunks?
No. Static variables last for the whole transaction, across every 200 record chunk.
That is why a static Boolean guard can wrongly skip the second and later chunks of a big load. A static Set of processed IDs is safer, because it only skips records already handled.
Q54: What happens to triggers when a Database call with allOrNone false has failed rows?
Salesforce rolls back, then retries the good rows and fires triggers again. As a result, triggers must be safe to run twice.
Interview tip: tie this to idempotent logic. Triggers that create records must not create them twice.
Q55: Can a before insert trigger read lookup parent fields from Trigger.new?
No. Only the lookup ID is set on the record, not the parent’s fields.
So c.Account.Industry is null in the trigger even if the account has an industry. Collect the AccountIds in a Set, query the accounts once into a Map, and read the parent fields from the Map.
Q56: Can you call a future method from every trigger run?
No. A transaction can make only 50 future calls, and a big load runs the trigger several times.
Collect the IDs and make one future or queueable call per chunk, not one per record. A queueable is usually the better choice, because it accepts sObjects and can be monitored.
Q57: Can you trust formula field values in a before trigger?
Not always, because formulas may not reflect the new field values yet. So call Formula.recalculateFormulas or compute the value in code.
Q58: Does a trigger fire when a formula field’s value changes?
No. Formula fields are calculated when read, so a change in their value is not a save. If you need to react to it, watch the fields the formula uses instead.
Q59: How do you write a trigger that works for both insert and update?
List both events and branch on Trigger.isInsert, or use shared logic with oldMap null checks. So one method serves both.
Scenario-Based Apex Trigger Interview Questions
Scenario-based Apex Trigger Interview Questions ask you to write or fix a trigger live.
Questions on Writing Triggers
Q60: Set a default Level__c of Beginner on new courses.
Use before insert and set c.Level__c = ‘Beginner’ when it is blank.
Example: for (Course__c c : Trigger.new) { if (String.isBlank(c.Level__c)) c.Level__c = ‘Beginner’; } No DML is needed, because before trigger changes save with the record. A default value on the field or a before save flow can also do this without code.
Q61: Create a welcome task when an enrolment is inserted.
Use after insert, build Task records in a List and insert them once. Then the task can use the enrolment Id.
Q62: Update an account field when any of its contacts change.
Use after insert, update, delete and undelete on Contact. Collect AccountIds, query and update accounts once.
Q63: Count active enrolments on each course without a roll-up field.
Use an after trigger on Enrolment__c, then run an aggregate query grouped by Course__c. Finally, update the courses in one DML.
Interview tip: mention handling delete and undelete too. Most candidates forget them.
Q64: Stop users changing Fee__c after the course starts.
Use before update and compare old and new values when Start_Date__c is in the past. Then call addError.
Q65: Write a trigger that stops duplicate enrolments for the same student and course.
Use before insert. Build a key like studentId + courseId for each new record, query existing enrolments for those students and courses, and call addError on new records whose key already exists. Also check for duplicates within the same chunk with a Set of keys.
Q66: Copy the account owner to new opportunities.
Use before insert, query owners for the AccountIds and set OwnerId. So the value saves with the record.
Questions on Fixing Triggers
Q67: A trigger fails with “Too many SOQL queries: 101” on a data load. Why?
A query sits inside a loop, so each record uses one query and the 101st fails.
Data loads send 200 records per chunk, so this shows up on loads, not on single saves. Move the query out of the loop: collect IDs in a Set, query once into a Map, and read from the Map inside the loop.
Q68: A trigger throws “Record is read-only” in after update. How do you fix it?
The trigger changes Trigger.new in an after trigger, where the records are read only.
Make the change in before update instead. If it must happen after the save, query the records again and update the copies, with a recursion guard.
Q69: A trigger fails with “Maximum trigger depth exceeded”. What happened?
The trigger updates records that fire it again in a loop. So add a recursion guard with a static Set of Ids.
Follow-up you may get: What is the trigger depth limit? 16 levels of recursive trigger calls.
Q70: newMap.get(rec.Id) returns null in before insert. Why?
New records have no Id, and newMap is not available in before insert. So use Trigger.new instead.
Q71: Only the first 200 records were processed in a 600-row load. Why?
A static Boolean guard stopped later chunks. So track processed Ids in a static Set instead.
Q72: A trigger callout fails with “Callout from triggers are currently not supported”. Fix it.
Move the callout to a Queueable or future method with callout=true. Then enqueue it from the trigger.
Q73: A trigger works in the UI but fails when an integration loads data. Why?
The integration sends up to 200 records at a time, so code that queries or does DML inside a loop breaks limits. It may also run as a user with different access. Add bulk tests with 200 records and test as the integration user.
Q74: Two triggers on Case conflict in random order. How do you fix it?
Merge them into one trigger with one handler. So the order becomes fixed and clear.
Use Trigger Explorer in Setup to see every trigger and flow on the object, then move all the logic into one handler with a clear order.
A Real Apex Trigger Interview Questions Answer
A classic live task is “keep a count of enrolments on each course, for any data change”. Here is a strong answer.
trigger EnrolmentTrigger on Enrolment__c (after insert, after update, after delete, after undelete) {
Set<Id> courseIds = new Set<Id>();
for (Enrolment__c e : Trigger.isDelete ? Trigger.old : Trigger.new) {
courseIds.add(e.Course__c);
if (Trigger.isUpdate) {
courseIds.add(Trigger.oldMap.get(e.Id).Course__c);
}
}
courseIds.remove(null);
Map<Id, Course__c> updates = new Map<Id, Course__c>();
for (Id cid : courseIds) {
updates.put(cid, new Course__c(Id = cid, Enrolment_Count__c = 0));
}
for (AggregateResult ar : [
SELECT Course__c cid, COUNT(Id) total
FROM Enrolment__c
WHERE Course__c IN :courseIds
GROUP BY Course__c
]) {
updates.get((Id) ar.get('cid')).Enrolment_Count__c = (Integer) ar.get('total');
}
update updates.values();
}
Explain that the trigger collects both old and new course Ids, so moved enrolments update both courses. Next, one aggregate query counts children, and courses with none reset to zero. Finally, one update saves every course. In real code, move this logic to a handler class.
Common Mistakes with Apex Trigger Interview Questions
- Writing queries or DML inside loops.
- Changing Trigger.new in after triggers.
- Using Trigger.newMap in before insert.
- Making callouts directly from triggers.
- Writing several triggers for the same object and event.
Best Practices for Answering Apex Trigger Interview Questions
- Say which event you chose and why, before or after.
- Always write for 200 records and say so.
- Keep the trigger thin and call a handler class.
- Mention a recursion guard when the trigger updates records.
- Add a bulk test to every trigger answer.
Official Resources
- Triggers (Apex Developer Guide)
- Trigger Context Variables (Apex Developer Guide)
- Triggers and Merge Statements (Apex Developer Guide)
Quick Recap
- Apex Trigger Interview Questions cover events, context variables, bulk design and scenarios.
- Before triggers change the same record without DML.
- After triggers have Ids and change other records.
- Trigger.newMap is not available in before insert.
- Keep one trigger per object with a handler class.
What’s Next?
Next, continue with trigger framework and recursion interview questions, Part 11 of the series.


