Salesforce developer interview questions and answers
A developer round usually moves from Apex basics to triggers, then to limits, testing and a bit of LWC. This set follows that order, so you can practise the way the interview actually flows.
On this page (12 sections)
Apex fundamentalsTriggers and order of executionGovernor limits, async and large dataErrors you will be asked to fixTesting and debuggingIntegrationFlow, Agentforce and LWCTools and code qualityHow to prepareRelated question setsCommon questions about developer interviewsRelated resourcesQuestions in each topic go from beginner to advanced. Use On this page to jump to the topic you need.
Apex fundamentals
01What is the difference between Custom Settings and Custom Metadata Types?
What is the difference between Custom Settings and Custom Metadata Types?
Both store configuration. Custom Metadata Type records are metadata, so they deploy with your code and don't count against SOQL limits when read. Hierarchy Custom Settings can hold different values per user or profile, which is useful for bypass switches.
Default to Custom Metadata for configuration that should move between orgs, and Custom Settings when values differ by user or need to change often in production.
02What is the difference between SOQL and SOSL?
What is the difference between SOQL and SOSL?
SOQL (Salesforce Object Query Language) queries records from a single object at a time, similar to SQL SELECT statements. It returns records with specific fields. SOSL (Salesforce Object Search Language) searches across multiple objects simultaneously using text search. SOSL is faster for keyword searches but less precise. Use SOQL when you know which object to query; use SOSL when searching across objects by keyword.
03What are Custom Metadata Types and how are they used in Apex?
What are Custom Metadata Types and how are they used in Apex?
Custom Metadata Types store configuration data as metadata, not data. They're deployable, packageable, and accessible in Apex without SOQL counting against limits. Query them like objects: [SELECT Value__c FROM Config_Setting__mdt WHERE DeveloperName = 'MaxRetries']. They're ideal for settings that need to move between environments.
04What is the difference between Database.insert() and the insert DML statement?
What is the difference between Database.insert() and the insert DML statement?
The insert DML statement is all-or-nothing: if one record fails, the entire operation rolls back and throws an exception. Database.insert() accepts an allOrNone parameter. Set it to false for partial success, where successful records are committed and failed records are returned with errors via Database.SaveResult[]. Use Database methods for data migration or integration scenarios where partial success is acceptable.
05How do you implement error handling in Apex?
How do you implement error handling in Apex?
Use try-catch-finally blocks. Catch specific exceptions (DmlException, QueryException, CalloutException) before the generic Exception. Log errors with a custom logging framework: don't just System.debug(). In triggers, uncaught exceptions roll back the entire transaction. In batch jobs, exceptions in execute() don't stop the overall job. Create custom exception classes for business logic validation. Never swallow exceptions silently.
06How do you implement sharing in Apex?
How do you implement sharing in Apex?
Use 'with sharing' keyword to enforce the running user's sharing rules. Use 'without sharing' to bypass sharing (system context). 'inherited sharing' inherits the caller's sharing context. Best practice: always specify sharing explicitly. Use 'with sharing' for user-facing operations. Use 'without sharing' only for system utilities. For programmatic sharing, create __Share records with UserOrGroupId, AccessLevel, and RowCause.
07How do you implement pagination in Apex?
How do you implement pagination in Apex?
Three approaches:
- StandardSetController: built-in pagination for Visualforce with first(), last(), next(), previous().
- OFFSET/LIMIT in SOQL: simple but limited to 2000 offset.
- Cursor-based: use the last record's ID or a field value as the starting point for the next page.
For LWC, use wire with offset parameters or implement server-side cursor pagination. Cursor-based is most scalable for large data volumes.
08What is the difference between WITH SECURITY_ENFORCED and WITH USER_MODE?
What is the difference between WITH SECURITY_ENFORCED and WITH USER_MODE?
Both make a SOQL query respect the running user's object and field permissions. WITH SECURITY_ENFORCED throws an error if any field in the query is not accessible. WITH USER_MODE is newer and stronger: it also enforces sharing rules and works for DML through Database.insert(records, AccessLevel.USER_MODE).
Salesforce recommends user mode for new code, so it is the better answer in an interview.
09What is dynamic Apex and when do you use it?
What is dynamic Apex and when do you use it?
Dynamic Apex lets you write code that adapts at runtime: dynamic SOQL (Database.query()), dynamic DML, and Schema.describe methods for inspecting object/field metadata. Use it when building generic utilities, package development, or admin tools where the object or fields aren't known at compile time. Be careful with dynamic SOQL: always sanitize inputs to prevent SOQL injection.
10What are Apex Interfaces and how do you use them?
What are Apex Interfaces and how do you use them?
Interfaces define method signatures that implementing classes must provide. Common Salesforce interfaces: Database.Batchable (batch processing), Queueable (async processing), Schedulable (scheduled jobs), Comparable (sorting). Use interfaces for dependency injection and loose coupling in trigger frameworks. Define your own interfaces for service layers; this makes code testable and swappable. For example, an IPaymentService interface that can be implemented by Stripe or PayPal classes.
11How do you design for multi-currency in Apex?
How do you design for multi-currency in Apex?
Enable multi-currency in the org. Use CurrencyIsoCode field on records. For conversions, use CurrencyType and DatedConversionRate objects. In Apex, always use convertCurrency() in SOQL for reports and aggregations. Be aware that formula fields using currency fields auto-convert based on the record's currency. Test with multiple currencies in your test classes. For advanced needs, consider using dated exchange rates for historical accuracy.
Triggers and order of execution
12What is the difference between before and after triggers?
What is the difference between before and after triggers?
Before triggers execute before a record is saved to the database. Use them for field updates and validation because you can modify field values directly without additional DML. After triggers execute after the record is saved and has an ID. Use them when you need the record ID (for related record creation) or when updating records in related objects. You can't modify the triggering record's fields in an after trigger.
13Explain bulkification in Apex with an example.
Explain bulkification in Apex with an example.
Bulkification means writing code that efficiently handles multiple records at once, not just one. Instead of querying inside a for loop (which hits governor limits), collect all IDs first, run one SOQL query, then process the results. For example: instead of querying each account's contacts individually inside a loop, collect all Account IDs into a Set, then run one query: [SELECT Id FROM Contact WHERE AccountId IN :accountIds]. This is the single most important Apex best practice.
14What is the trigger framework pattern and why use it?
What is the trigger framework pattern and why use it?
A trigger framework separates trigger logic from the trigger itself. The trigger file only calls a handler class. The handler contains the actual business logic organized by trigger event (beforeInsert, afterUpdate, etc.). Benefits include: single trigger per object, easier testing, reusable logic, and cleaner code organization. Popular patterns include the Handler pattern and the TriggerFramework abstract class approach.
15How do you avoid recursive triggers?
How do you avoid recursive triggers?
Use a static Boolean variable in a helper class to track whether the trigger has already executed. Set it to true on first execution and check it at the start of the trigger. Another approach is using a static Set to track processed record IDs. Be careful with after-update triggers that perform DML on the same object; they naturally cause recursion. The framework approach handles this elegantly.
16Explain the Salesforce order of execution.
Explain the Salesforce order of execution.
When a record is saved, Salesforce follows a specific sequence:
- System validation.
- Before triggers.
- Custom validation rules.
- After triggers.
- Assignment rules.
- Auto-response rules.
- Workflow rules (with possible re-evaluation).
- Processes/Flows.
- Escalation rules.
- Rollup summary updates.
- Commit.
You need this order when debugging, for example, knowing that validation rules run after before triggers explains why you can set fields in before triggers that would otherwise fail validation.
Governor limits, async and large data
17What are governor limits and why do they exist?
What are governor limits and why do they exist?
Governor limits are runtime limits enforced by Salesforce to prevent any single tenant from monopolizing shared resources. Key limits include 100 SOQL queries per synchronous transaction, 150 DML statements, 6 MB heap size, and 10-second CPU time. They exist because Salesforce is multi-tenant: every org shares the same infrastructure. Writing efficient code that respects these limits is a core developer skill.
18What is the Limits class and how do you use it?
What is the Limits class and how do you use it?
The Limits class provides methods to check governor limit consumption at runtime. Key methods: Limits.getQueries() (SOQL used), Limits.getDMLStatements() (DML used), Limits.getCpuTime(), Limits.getHeapSize(). Use corresponding getLimitXxx() methods for maximum allowed. Use these for debugging and monitoring: add limit checks to your logging framework. Example: if (Limits.getQueries() > 80) { System.debug('WARNING: Approaching SOQL limit'); }
19What is the difference between synchronous and asynchronous Apex?
What is the difference between synchronous and asynchronous Apex?
Synchronous Apex runs immediately and blocks until completion: triggers, classes, and controllers. Asynchronous Apex runs in the background with higher governor limits. Types include: Future methods (simple async calls), Queueable Apex (chaining jobs, passing complex types), Batch Apex (processing large data volumes), and Scheduled Apex (time-based execution). Choose based on use case: batch for bulk processing, queueable for chaining, future for callouts from triggers.
20How do you handle governor limits when processing large datasets?
How do you handle governor limits when processing large datasets?
Strategies by limit type: SOQL (100 limit); bulkify queries, use Maps. DML (150 limit): collect records in lists, single DML after loop. Heap (6MB): use SOQL for loops, process in chunks. CPU (10s): optimize logic, move to async. For very large datasets: use Batch Apex (50M records via QueryLocator). For callouts: use Queueable with chaining. Always measure limits in testing with Test.startTest()/stopTest().
21What are Big Objects and when do you use them?
What are Big Objects and when do you use them?
Big Objects store very large volumes of data, billions of records, with consistent performance. They suit history and archive data, such as old orders or audit records.
Limits: you query them only on their index fields, they don't support triggers, Flows or standard reports, and they are written with Database.insertImmediate().
Errors you will be asked to fix
22What is a Mixed DML error and how do you fix it?
What is a Mixed DML error and how do you fix it?
It happens when one transaction changes setup objects (such as User, Group or PermissionSetAssignment) and non-setup objects (such as Account) together. Salesforce blocks this because setup changes affect sharing.
Fix it by moving one of the operations to a separate transaction, usually with a Queueable or @future method. In test classes, wrap the setup change in System.runAs().
23How do you fix 'UNABLE_TO_LOCK_ROW' errors?
How do you fix 'UNABLE_TO_LOCK_ROW' errors?
The error means two transactions tried to update the same record, or child records of the same parent, at the same time. It is common in data loads and integrations with data skew.
Fixes: sort records by parent ID before loading, reduce batch size, avoid many children under one parent, use FOR UPDATE only when needed, and add retry logic for integrations.
Testing and debugging
24How do you write effective test classes?
How do you write effective test classes?
Good test classes cover three scenarios: positive (expected behavior), negative (error handling), and bulk (200+ records). Create your own test data: don't rely on org data. Use @testSetup for shared data creation. Test as different user profiles using System.runAs(). Assert outcomes, don't just execute code. Aim for meaningful assertions, not just coverage. Minimum 75% coverage is required for deployment, but aim for 90%+.
25How does Apex testing differ from traditional unit testing?
How does Apex testing differ from traditional unit testing?
Apex tests run in an isolated context: they don't see org data by default (unless @isTest(SeeAllData=true)). Tests must create their own data. The platform enforces minimum 75% code coverage for deployment. Tests validate governor limit compliance automatically. System.runAs() lets you test as different users. Test.startTest()/stopTest() provides fresh governor limits for the code under test.
26How do you debug a problem that only happens in production?
How do you debug a problem that only happens in production?
Set a trace flag for the affected user and reproduce the issue, then read the debug log, or replay it in VS Code with the Apex Replay Debugger. Check your error logging object or Platform Event logs if you have them.
If you can't reproduce it, compare data and configuration between production and a full sandbox, because the cause is often data-specific.
Integration
27What are Named Credentials and External Credentials?
What are Named Credentials and External Credentials?
A Named Credential stores an endpoint URL: an External Credential stores how to authenticate (OAuth, API key, JWT and so on) and which users can use it through permission sets. Apex calls the endpoint with callout:My_Named_Credential and never sees the secret.
This keeps secrets out of code and makes it easy to point sandboxes and production at different systems.
28How do you handle callouts from triggers?
How do you handle callouts from triggers?
You cannot make HTTP callouts directly from a trigger because triggers run in a transaction context. Instead, use a @future(callout=true) method or Queueable Apex with Database.AllowsCallouts. The trigger calls the async method, which then makes the callout. For complex scenarios with multiple callouts, use Queueable chaining. Always handle callout failures gracefully with try-catch blocks.
29What is Platform Events and when would you use it?
What is Platform Events and when would you use it?
Platform Events enable event-driven architecture in Salesforce. They're custom events that can be published and subscribed to by Apex, Flows, or external systems. Use them for decoupling processes, for example, a trigger publishes an event when a large deal closes, and separate subscribers handle notifications, analytics updates, and external system sync independently. They support replay for reliability.
30How do you implement custom Apex REST APIs?
How do you implement custom Apex REST APIs?
Use @RestResource annotation on a class with a urlMapping. Define methods with @HttpGet, @HttpPost, @HttpPut, @HttpPatch, @HttpDelete. Access parameters via RestContext.request. Return data through RestContext.response or directly. Handle errors with proper HTTP status codes. Secure endpoints using Connected Apps and OAuth. Always bulkify your API logic; it may receive multiple records.
31What is Change Data Capture and how do you subscribe in Apex?
What is Change Data Capture and how do you subscribe in Apex?
Change Data Capture publishes events when records are created, updated, deleted, or undeleted. Subscribe via Apex triggers on the change event object (e.g., AccountChangeEvent). The event contains changedFields, changeType, and the full record. Use it for real-time integration: external systems can subscribe via CometD. Key advantage over triggers: CDC events include old and new field values, making differential sync efficient.
Flow, Agentforce and LWC
32What is the difference between Visualforce and LWC?
What is the difference between Visualforce and LWC?
Visualforce is server-side rendered: each interaction requires a server round-trip. LWC is client-side, using standard web components for faster rendering. LWC has better performance, smaller payloads, and makes better use of browser caching. Visualforce still works for complex page overrides and PDF generation. New development should use LWC. Key migration path: use Lightning Out to embed LWC in Visualforce pages during gradual migration.
33What are Invocable Methods and when do you use them?
What are Invocable Methods and when do you use them?
Invocable Methods (@InvocableMethod) expose Apex logic to declarative tools: Flows, Process Builder, REST API, and Einstein Bots. They accept a List of inputs and return a List of outputs. Use them when Flow can't handle complex logic: callouts, complex calculations, or multi-object operations. Define @InvocableVariable for input/output parameters. They bridge the gap between declarative and programmatic development.
34How do you run a Flow from Apex?
How do you run a Flow from Apex?
Create an instance of the Flow with input variables and start it:
Map<String, Object> inputs = new Map<String, Object>{ 'recordId' => acc.Id };
Flow.Interview flow = Flow.Interview.createInterview('Account_Followup', inputs);
flow.start();
Object result = flow.getVariableValue('outputMessage');This is useful when admins own the business logic in Flow but Apex needs to trigger it.
35How do you call an external system from LWC?
How do you call an external system from LWC?
Usually through an Apex method that makes the callout with a Named Credential, because the browser can't safely hold credentials and CORS rules often block direct calls.
If the external API is public and allows it, you can call it from JavaScript after adding the URL to Trusted URLs (formerly CSP Trusted Sites), but this is rare for business data.
36How do you build an Agentforce action with Apex?
How do you build an Agentforce action with Apex?
Write a class with an @InvocableMethod and clear label and description values, with @InvocableVariable inputs and outputs that also have descriptions. Then add it as an action to an agent's subagent in Agentforce Builder.
The descriptions matter: the reasoning engine reads them to decide when to call the action and what to pass, so vague descriptions cause wrong calls. Also check what the agent user can access, because the action runs with its permissions.
37How do you make a Lightning page load faster when Apex is slow?
How do you make a Lightning page load faster when Apex is slow?
Mark read-only methods @AuraEnabled(cacheable=true) so results are cached on the client, return only the fields the component needs, and load secondary data lazily, for example when a tab is opened.
On the Apex side, make queries selective, avoid queries in loops and consider Platform Cache for data that many users read.
Tools and code quality
38What is Salesforce Code Analyzer?
What is Salesforce Code Analyzer?
A free tool from Salesforce that scans Apex, LWC and Flow for security problems, performance issues and bad practices, using rule engines such as PMD and ESLint. It runs from the Salesforce CLI or VS Code.
Teams run it in the CI pipeline so problems are caught in the pull request, not in a code review weeks later.
39What is Salesforce DX and how do scratch orgs help?
What is Salesforce DX and how do scratch orgs help?
Salesforce DX is source-driven development: your metadata lives in Git, and you use the Salesforce CLI to deploy and test. Scratch orgs are short-lived orgs created from a definition file, so every developer or CI run starts from a clean, known state.
Mention the full flow: create a scratch org, push source, run tests, open a pull request, deploy to a sandbox, then to production.
40How do you approach a code review of another developer's trigger?
How do you approach a code review of another developer's trigger?
I check that it follows the one-trigger-per-object pattern with a handler, is bulk-safe, has no SOQL or DML in loops, respects security (user mode), avoids recursion and has tests with real assertions for single and bulk records.
I explain each comment with the reason, so the developer learns the pattern instead of just fixing one line.
How to prepare
Master bulkification. This is the #1 topic in developer interviews. Be able to refactor a non-bulkified trigger on the spot.
Know the order of execution cold. Many tricky interview questions become easy once you understand when triggers, validations, and flows run.
Practice writing test classes. Interviewers often ask you to write or review test code. Know positive, negative, and bulk test patterns.
Understand async patterns. Know when to use @future vs Queueable vs Batch vs Scheduled, and be able to explain trade-offs.
Strengthen your preparation by exploring related question banks in the same topic cluster. Each guide covers a unique angle of salesforce developer interviews: pick the one closest to the role you are targeting.
Common questions about developer interviews
What does a Salesforce Developer interview cover end-to-end?
Expect five buckets: (1) Apex fundamentals (collections, triggers, async); (2) SOQL/SOSL and bulkification; (3) governor limits and order of execution; (4) LWC basics including @wire vs imperative; (5) testing with Apex test classes and Jest. Senior interviews add design patterns and integration questions.
How much LWC do I need to know for a Developer interview?
Enough to discuss decorators (@api, @wire), lifecycle hooks, parent-child events, Lightning Data Service vs Apex, and Jest testing. You don't need to be a UI specialist, but every modern Salesforce Developer is expected to be productive in LWC.
What's the most common red flag in a Salesforce Developer interview?
Writing SOQL or DML inside a for-loop on a whiteboard problem. It's the canonical test of bulkification: failing it signals lack of production experience regardless of years on a resume.
How do I prepare for the order-of-execution question?
Memorize the sequence: system validation → before triggers → custom validation → after triggers → assignment/auto-response → workflow rules → process/flows (after) → escalation rules → roll-up summaries → commit. Then practice explaining why a value set in a before-trigger survives a validation rule.
Should I use Queueable or @future for async work?
Queueable in almost every modern case; it accepts SObjects and complex types, supports chaining, returns a job ID for monitoring, and has higher limits. @future remains useful only for very simple fire-and-forget scenarios with primitive parameters.