Salesforce developer interview questions
Salesforce developer interviews test whether your Apex survives a full transaction: 200 records in a trigger, queries and DML under the limits, and tests that assert a real outcome. Practice those skills as graded drills on ApexSensei, first in the browser and then in your own Developer org, instead of only memorizing a list. The Apex interview questions below turn the common topics into code you write and run.
Practice these as drills Create a free account
What a hiring manager asks
How do you update many records without spending a DML statement per row?
Change the fields in memory, then save the list once after the loop. A save inside the loop spends one DML statement per row, and after 150 in a transaction the next save throws LimitException. Build one list and pass it to a single update, insert, or delete.
Bulk update once Mark parent Accounts in bulk
Why do teams keep one trigger per object?
Salesforce does not guarantee the order in which several triggers on the same object run. Keep one trigger per object, have it call a handler, and let the handler call the services, so the order lives in code you can read. The handler can also route each event, such as before insert or after update, to its own method.
Apex trigger best practices Move Opportunity logic to a handler
What does a governor limit stop?
A governor limit caps queries, rows retrieved, DML, CPU time, and callouts in one transaction. Crossing a limit throws LimitException, which rolls the transaction back and cannot be caught. The caps reset per transaction, so moving heavy work into an asynchronous job gives it a fresh set.
Apex governor limits Measure governor headroom Apex governor limits explained
When do you use SOQL, and when do you use SOSL?
SOQL reads the fields you name on the objects you name, with filters and relationships, and returns rows you can loop over. SOSL searches text across several objects at once, which is what you want when you do not yet know which object holds the word. A transaction allows 100 SOQL queries and 20 SOSL queries, so SOSL is the narrower budget.
SOQL query builder Search names with SOSL SOQL queries explained
When is Queueable the right job, and when is Batch?
Queueable runs one job, can carry state in its member variables, and can chain another job from its execute method. Batch walks a large query in chunks through start, execute, and finish, which is what you want when one transaction cannot hold all the rows. Batch processes records in batches you size, 200 by default, and each batch runs as its own transaction with a fresh set of limits.
Queueable Apex Batch Apex Carry Account work in a Queueable Build a Batch lifecycle
What does a useful test class assert?
It creates its own records, calls the code, and asserts the outcome you care about. A test that only runs the method still counts toward coverage, but it passes even when the result is wrong. Wrap the call in Test.startTest and Test.stopTest so any asynchronous work finishes before you assert.
Apex test classes Assert service outcomes Prove bulk behavior
Apex interview questions
Apex interview questions ask how the code behaves when the transaction is full: 200 trigger rows, a query that might miss, and a test that has to fail when the outcome is wrong.
How do you keep a trigger under the SOQL limit when it receives 200 records?
Collect the Ids from Trigger.new, query once with a WHERE Id IN :ids filter, and keep the rows in a Map by Id. A query inside the for loop spends one of the 100 synchronous SOQL queries per record, so 200 records fail partway through. One query plus a Map lookup keeps the whole trigger at a single query.
Fix a query inside a loop Mark parent Accounts in bulk Apex governor limits
What should the trigger itself contain?
A few lines that call a handler. The handler reads the old and new lists and calls a service. Business rules do not live in the trigger body, where the next person cannot find them.
Move Opportunity logic to a handler Apex trigger best practices
How do you check governor-limit headroom before you do more work?
The Limits class reports what this transaction has already used, through Limits.getQueries, Limits.getDmlStatements, and Limits.getCpuTime, each paired with a getLimit version for the cap. Read it before a large query or save, because a try/catch cannot swallow LimitException once you cross a limit. Comparing the used value with its cap tells you how much headroom is left.
Measure governor headroom Apex governor limits explained
Why is assigning a SOQL query to one sObject risky?
Assigning a SOQL result straight to one sObject throws QueryException when the filter matches zero rows, and it also throws when more than one row comes back. Assign the query to a list instead, then decide what zero, one, and many rows each mean for your code. A Map keyed by Id is the usual way to handle the many case.
Single-row query: zero or many rows SOQL query builder
What belongs in a test besides the method call?
Records the test inserts itself, plus an assertion on the field, the row count, or the exception you expect. By default a test class sees no existing org data, so the rows it creates are the only ones it works with. A test data factory keeps that setup in one place, so each test builds the same baseline instead of depending on whatever is in the org.
Build a test data factory Assert service outcomes Apex test classes
Practice these answers, don't just read them
Reading the answers is the start; the real work is writing the Apex. The drills linked above run in your browser first, with no org, and later ones run in your own Developer org. Some run as anonymous Apex, and others deploy a class and run its tests.
When a check fails, the drill shows what it expected and what your code gave instead. Miss the same check twice and a hint opens up, so you are not left guessing.
The best way to practice Apex PD1 coding practice PD1 practice exam