Salesforce Developer Interview Questions: Apex, SOQL and LWC Answered
The questions Salesforce developer interviews keep coming back to, with answers checked against the current Apex and LWC docs: trigger handlers and Queueable Apex, SOQL in user mode and governor limits, LWC lifecycle hooks and events, the order of execution, and data security. Apex here was checked against the Apex Developer Guide, not run.
Salesforce developer interviews rarely stop at syntax. Interviewers ask why you'd pick a trigger handler, what happens to your field update later in the save, and when a lifecycle hook runs. This guide is for developers preparing for those questions, from a first Salesforce role to a senior one. It covers Apex triggers and async Apex, secure SOQL, Lightning Web Components (LWC), the order of execution, and how to prepare.
This is part 3 of the Salesforce Interview Series. The previous part covers Salesforce AI interview questions on Agentforce, Prompt Builder and Data 360, and part 1 is a revision guide to Apex, LWC, triggers and system design.
Key takeaways
- Keep triggers thin: one trigger per object that hands work to a handler class, and pass record IDs, not sObjects, to async jobs.
- Know the order of execution: before-save flows, then before triggers, then validation rules, then after triggers and after-save flows.
- Query in user mode (
WITH USER_MODE) and uselwc:ifandrenderedCallback()correctly.
Why Salesforce interviews are hard
Salesforce isn't one tool. A developer works with declarative automation like Flow, plus Apex, SOQL, LWC and the platform's security model. Interviewers want someone who understands how these pieces interact and how to build code that scales.
Governor limits are the per-transaction caps that the Apex runtime enforces, such as 100 SOQL queries in a synchronous transaction (Execution Governors and Limits). A developer who designs for them from the first line writes code that doesn't fail in production. That applies to a junior developer and to an architect leading a large build.
Architectural concepts with practical examples
Here are the areas that come up most, with examples that show understanding beyond memorized answers.
Apex: triggers, async processing and best practices
You need to know trigger frameworks, the order of execution, and when to use asynchronous Apex.
Instead of putting business logic in the trigger, show a handler class. It tells the interviewer you think about maintainability and testing.
// AccountTrigger.trigger
trigger AccountTrigger on Account (before insert, before update, after insert, after update) {
if (Trigger.isBefore) {
if (Trigger.isInsert) {
AccountTriggerHandler.onBeforeInsert(Trigger.new);
} else if (Trigger.isUpdate) {
AccountTriggerHandler.onBeforeUpdate(Trigger.new, Trigger.oldMap);
}
} else if (Trigger.isAfter) {
if (Trigger.isInsert) {
AccountTriggerHandler.onAfterInsert(Trigger.new);
} else if (Trigger.isUpdate) {
AccountTriggerHandler.onAfterUpdate(Trigger.new, Trigger.oldMap);
}
}
}
// AccountTriggerHandler.cls
public with sharing class AccountTriggerHandler {
public static void onBeforeInsert(List<Account> newAccounts) {
for (Account acc : newAccounts) {
if (acc.AnnualRevenue == null) {
acc.AnnualRevenue = 0; // default revenue
}
}
}
public static void onAfterInsert(List<Account> newAccounts) {
// Heavy work goes async. Pass IDs; the job re-queries fresh data.
Set<Id> accountIds = new Map<Id, Account>(newAccounts).keySet();
System.enqueueJob(new UpdateContactsJob(accountIds));
}
public static void onBeforeUpdate(List<Account> newAccounts, Map<Id, Account> oldAccountsMap) {
// logic specific to before update
}
public static void onAfterUpdate(List<Account> newAccounts, Map<Id, Account> oldAccountsMap) {
// logic specific to after update
}
}
// UpdateContactsJob.cls
public with sharing class UpdateContactsJob implements Queueable {
private final Set<Id> accountIds;
public UpdateContactsJob(Set<Id> accountIds) {
this.accountIds = accountIds;
}
public void execute(QueueableContext context) {
List<Contact> contacts = [
SELECT Id, AccountId FROM Contact
WHERE AccountId IN :accountIds
WITH USER_MODE
];
// update the related contacts here (details omitted)
}
}
Why Queueable and not @future? Salesforce's Queueable Apex page recommends Queueable over future methods, and Queueable jobs can be chained (Queueable Apex). If an interviewer asks for @future anyway, remember its main rule: future methods take only primitives or collections of primitives, never sObjects (Future Annotation). Pass a Set<Id>, as above.
| Option | What it does | Trade-off | When to use |
|---|---|---|---|
@future |
Runs one static method later | Primitive parameters only, no job ID, no chaining | Legacy code; Salesforce now recommends Queueable |
| Queueable Apex | Runs a job class with its own state | One job per enqueue; chain depth is limited | Follow-up work after a trigger, callouts (with Database.AllowsCallouts) |
| Batch Apex | Splits a query into chunks; each execute gets fresh limits |
Slower to start, more code (start, execute, finish) |
Large data volumes, up to 50 million records |
The table follows the Queueable Apex and Use Batch Apex pages; Queueable jobs return a job ID and can hold sObjects as member variables, which future methods can't.
Fixed in this version
An earlier version of this post passed List<Account> to an @future method, which doesn't compile. It also put validation rules in the wrong place in the order of execution. Both are corrected in this version.
The handler pattern pairs with the order of execution. For a save, Salesforce runs before-save record-triggered flows, then before triggers, then system and custom validation rules and duplicate rules. Next comes the save (not yet committed), then after triggers, and later after-save record-triggered flows (Triggers and Order of Execution). So a value your before trigger sets can fail a validation rule, and the save stops even though your trigger code ran cleanly. Keep that in mind when you debug.
SOQL: efficiency and data security
A simple query isn't enough. You need selective queries, protection against SOQL injection, and object and field-level security.
// Relationship query that enforces the running user's permissions
List<Account> accountsWithContacts = [
SELECT Id, Name, (SELECT Id, FirstName, LastName, Email FROM Contacts)
FROM Account
WHERE AnnualRevenue > 100000
WITH USER_MODE
LIMIT 200
];
for (Account acc : accountsWithContacts) {
System.debug('Account: ' + acc.Name);
for (Contact con : acc.Contacts) {
System.debug(' Contact: ' + con.FirstName + ' ' + con.LastName);
}
}
WITH USER_MODE applies the running user's sharing rules, field-level security and object permissions. It processes every clause, including WHERE, and reports all field-level security errors at once, so prefer it to the older WITH SECURITY_ENFORCED clause (Set an Access Mode for Database Operations). The same page notes a newer change worth mentioning in an interview: in API version 67.0 and later, Apex database operations run in user mode by default, while 66.0 and earlier default to system mode. Write the clause anyway so a reviewer can see the intent.
LWC: lifecycle, data flow and component events
You need to know the component lifecycle, how the wire service loads data, and how components talk to each other.
// myAccountList.js
import { LightningElement, wire } from 'lwc';
import getAccounts from '@salesforce/apex/AccountController.getAccounts';
const COLUMNS = [
{ label: 'Name', fieldName: 'Name' },
{ type: 'action', typeAttributes: { rowActions: [{ label: 'Select', name: 'select' }] } }
];
export default class MyAccountList extends LightningElement {
columns = COLUMNS;
@wire(getAccounts)
accounts;
handleRowAction(event) {
const { action, row } = event.detail;
if (action.name === 'select') {
this.dispatchEvent(new CustomEvent('accountselected', { detail: row.Id }));
}
}
}
<!-- myAccountList.html -->
<template>
<lightning-card title="My Accounts" icon-name="standard:account">
<template lwc:if={accounts.data}>
<lightning-datatable
key-field="Id"
data={accounts.data}
columns={columns}
onrowaction={handleRowAction}>
</lightning-datatable>
</template>
<template lwc:elseif={accounts.error}>
<div>Error loading accounts: {accounts.error.body.message}</div>
</template>
</lightning-card>
</template>
// AccountController.cls
public with sharing class AccountController {
@AuraEnabled(cacheable=true)
public static List<Account> getAccounts() {
return [SELECT Id, Name FROM Account WITH USER_MODE ORDER BY Name LIMIT 50];
}
}
Two details interviewers check. First, a datatable row action passes event.detail.action and event.detail.row, not a bare ID (lightning-datatable). Second, the legacy if:true and if:false directives are no longer recommended; use lwc:if, lwc:elseif and lwc:else (Render HTML Conditionally).
Other LWC concepts to know: @api makes a property public, @wire connects data, and @track is only needed to observe changes inside a plain object or array. Every field is already reactive when you assign it a new value (Reactivity for Fields, Objects, and Arrays). Also be ready on component composition, standard versus custom events, and when to call Apex imperatively instead of through the wire service.
The component above was tested with @salesforce/sfdx-lwc-jest@7.9.0 (Jest with a mocked wire adapter, 2026-10-30): it renders the table, shows the error branch, and fires accountselected with the row ID. The Apex in this post was checked against the Apex Developer Guide but not deployed to an org.
How to prepare
- Practice in a Developer Edition org. Recreate scenarios, debug existing code, and hit a governor limit on purpose to see what the error looks like.
- Understand the "why". For trigger frameworks, async Apex and LWC hooks, ask what problem each solves and when you'd use it. Interviewers probe this.
- Read the official docs. Start with the Apex Developer Guide pages on governor limits and the order of execution, then the LWC Developer Guide on lifecycle hooks.
- Do mock interviews. Explain your thinking out loud while you write code in a shared editor. It shows gaps in how you explain, not only in what you know.
- Build small projects. A trigger, a Queueable job and an LWC that work together give you concrete examples to talk about.
Trade-offs, gotchas and failure modes
- Governor limits: A query inside a loop over
Trigger.newfails once a data load sends 200 records. Bulkify: query once, store results in aMap, then loop. - Order of execution surprises: A field set in a
before updatetrigger can be changed again by an after-save record-triggered flow that updates the same record. - Security gaps: Sharing keywords don't enforce object or field permissions (sharing keywords). Use user mode or
Security.stripInaccessible(), which strips fields the user can't access from query results or from records before DML (stripInaccessible). - Flow or Apex: Apex for a simple field default adds code to maintain; a Flow for complex, high-volume logic can hit Flow limits. Workflow Rules and Process Builder are out: Salesforce ended support for both on December 31, 2025 (end of support).
- Testing gaps: Test with 200 records, not one, and cover positive, negative and boundary cases.
Frequently asked questions
How do you handle large data volumes in Apex without hitting governor limits?
Use Batch Apex for big jobs: each execute call is its own transaction with fresh limits, and a Database.QueryLocator can return up to 50 million records (Use Batch Apex). Use Queueable Apex for chained steps or callouts. For near real-time sync, platform events or Change Data Capture keep the work out of the user's transaction.
Explain the order of execution. Why does it matter?
It's the sequence Salesforce follows when a record is saved, from loading the record to committing the transaction. It matters because it tells you how triggers, record-triggered flows and validation rules interact. Knowing it helps you predict overwrites, debug failed saves, and pick the right tool for a requirement.
When would you use an Apex trigger instead of a Flow?
Use Apex when the logic is complex, needs fine control over errors and transactions, handles high volumes, or needs reusable code in a pattern like a trigger handler. Use a record-triggered Flow when an admin should be able to maintain simple logic. Don't build new Workflow Rules or Process Builder processes; both are past end of support.
What's the difference between connectedCallback and renderedCallback in LWC?
connectedCallback() fires when the component is inserted into the DOM, which makes it a good place for setup such as fetching data. It can fire more than once, for example when a list is reordered (connectedCallback()). renderedCallback() runs after every render. Updating state inside it can cause an infinite loop, so guard one-time work with a flag such as hasRendered (renderedCallback()).
How do you keep Apex code secure?
Declare with sharing explicitly, run queries and DML in user mode (WITH USER_MODE, insert as user), and use Security.stripInaccessible() when you need to drop fields the user can't see. For dynamic SOQL, use bind variables instead of string concatenation to block SOQL injection.
Your next step: build it, break it, fix it
Getting good at Salesforce development isn't about memorizing answers. It's about knowing what the platform can do and where its limits are. I've built my career on finding the most efficient, automated ways to deliver solutions, and that means working with the platform's architecture, not around it.
So prepare for the job, not only the interview. Pick one topic from this guide, such as Queueable Apex or an LWC that loads and edits data. Build it, test it with 200 records, try to break it, and then fix it.
Sources
Verified against the sources below on October 30, 2026. Products and docs change often: check the linked sources if something looks different.
- Apex Developer Guide: Triggers and Order of Execution
- Apex Developer Guide: Execution Governors and Limits
- Apex Developer Guide: Future Annotation
- Apex Developer Guide: Queueable Apex
- Apex Developer Guide: Use Batch Apex
- Apex Developer Guide: Set an Access Mode for Database Operations
- Apex Developer Guide: Enforce Security with the stripInaccessible Method
- Apex Developer Guide: Use the with sharing, without sharing, and inherited sharing Keywords
- LWC Developer Guide: connectedCallback() and disconnectedCallback()
- LWC Developer Guide: renderedCallback()
- LWC Developer Guide: Render HTML Conditionally
- LWC Developer Guide: Reactivity for Fields, Objects, and Arrays
- Lightning Component Reference: lightning-datatable
- Salesforce Help: Workflow Rules and Process Builder End of Support
All 3 parts in this series
- Part 01Salesforce Interview Preparation: Apex, LWC, Triggers & System Design
- Part 02Salesforce AI Interview Questions: Agentforce, Prompt Builder, Data 360
- Part 03Salesforce Developer Interview Questions: Apex, SOQL and LWC Answered



Comments
Loading comments...