Hey friends,
Apex interviews for junior and mid-level roles keep coming back to the same dozen things: what Apex is, collections, SOQL, DML, triggers, exceptions, tests and deployment. Below are 12 questions on those topics, each with a short answer checked against Salesforce's docs and a note on how to say it, so you sound like someone who has actually run the code.
I cannot tell you what any one company will ask, so I will not invent "real" questions. These are the fundamentals the platform makes unavoidable. The answers come from Salesforce's Apex Developer Guide, the SOQL reference and Trailhead, checked on October 28, 2026, and each links to its page. The code was checked for syntax only, not run in an org. For the harder topics, such as the order of execution, sharing and Lightning Web Components, see my companion post, Salesforce developer interview questions.
How to answer an Apex question
Here is a simple pattern. It is my own advice, not Salesforce's.
- Say the rule in one sentence. Interviewers want to hear that you know the answer before the detail.
- Give a tiny example. One line of code or one real object, like Account, makes it concrete.
- Name the trade-off. Most Apex answers are choices, so say when you would pick the other option.
- Say what you would check. If you do not remember a number, say which doc or class you would look at.
If you have not written Apex yet, start with my step-by-step path to learn Apex and practice in a Developer Edition org.
Language and data questions
1. What is Apex, and how is it different from Java?
Salesforce describes Apex as a strongly typed, object-oriented language with syntax that looks like Java. The differences are the point. Apex is hosted and runs entirely on the Salesforce platform, it is multitenant aware so the runtime guards against runaway code, and it has built-in support for DML, inline SOQL and SOSL, and unit tests. Apex also does not try to render user interface elements. Say it as: "Java-like, but hosted, data-focused and limited by governor limits."
2. What are a List, a Set and a Map?
Per the Collections page, a list is an ordered collection of elements distinguished by their indices. A set is an unordered collection with no duplicates. A map is a collection of key-value pairs where each unique key maps to a single value. Use a list when order matters, a set to remove duplicates or check membership, and a map to look up a record by ID. This prints 2, because the duplicate city is dropped:
For patterns with all three, see my Apex collections cheat sheet.
3. What is the difference between SOQL and SOSL?
SOQL queries records from an object you name, with a list of fields, a source object and conditions. The reference says to use SOSL when you do not know which object or field holds the data, or when you want to search several objects for a term. In Apex, both go in square brackets, and you can use a variable in a query if you put a colon before it. That is called a bind. My post on SOQL for beginners goes through the syntax.
4. What is the difference between a DML statement and a Database class method?
The Apex Developer Guide says both perform DML operations. A DML statement like insert throws an exception you can catch if any record fails. A Database method, like Database.insert, takes a second Boolean parameter. If you pass false, the remaining records can still succeed when one fails, and you get an array of result objects instead of an exception. The default is true. Use DML statements when you want an error to stop the flow, and Database methods when you want partial success and your code will inspect the failures.
The second account has no name, so it is expected to fail while the first one saves.
Triggers and errors
5. What is a trigger, and what is the difference between before and after?
A trigger is Apex attached to an object that runs when its records change. The trigger context variables page says Trigger.isBefore is true when the trigger fired before any record was saved, and Trigger.isAfter when it fired after all records were saved. It also says the records in Trigger.new can only be modified in before triggers. So: use before triggers to change or validate the incoming records, and after triggers when you need the saved record, such as its ID, to create related records.
6. Which trigger context variables should you know?
From the same page: Trigger.new is the list of new versions of the records and is available in insert, update and undelete triggers. Trigger.old holds the old versions, only in update and delete triggers. Trigger.newMap and Trigger.oldMap map IDs to records. Trigger.isInsert, isUpdate and isDelete tell you the operation, and Trigger.operationType gives it as an enum. Trigger.size is the number of records in the current batch. DML with more than 200 records is processed in batches, and the trigger runs for each batch, which is why you write trigger code to handle a list, not one record. I cover this further in my trigger best practices post.
7. How do you handle errors in Apex?
With try, catch and finally, per the Exception Statements page. The try block holds code that can fail, each catch block handles one exception type, and the finally block always runs, whether or not an exception was thrown. A try needs at least a catch or a finally. The follow-up: some exceptions cannot be caught. The page says that includes the limit exception, thrown when a governor limit is exceeded, and exceptions from failed assertions. In those cases, neither the catch nor the finally block runs.
8. What are governor limits, and why do they exist?
Apex runs in a multitenant environment where many customers share resources, so the runtime guards against runaway code. Code that breaks a limit fails with an error you cannot catch, as question 7 says. Give the reason first, then say you would check the current numbers in the docs rather than reciting them. The numbers are in my governor limits cheat sheet, and the developer interview post has a table.
Testing and deployment questions
9. How do you write a test class?
Per the Trailhead testing unit, test methods use the @IsTest annotation and live in classes annotated with @IsTest. Visibility does not matter for a test method, and a class used only for unit tests should be private. A good test sets up data, calls the code between Test.startTest() and Test.stopTest(), then asserts the result. This tests the Greeter class from my learn Apex post:
10. What do Test.startTest() and Test.stopTest() do?
The Apex Reference says code between them gets a new set of governor limits, and each test method can call each of them only once. After stopTest(), the original limits apply again. It also says that when stopTest() runs, all asynchronous processes started in the block run synchronously, so you can assert on their results.
11. How much code coverage do you need to deploy to production?
The testing page says unit tests must cover at least 75% of your Apex code, all of those tests must complete successfully, every trigger must have some coverage, and all classes and triggers must compile. It also says System.debug calls and test classes do not count. The page is clear that the percentage is not the goal: cover every use case, positive and negative, single record and bulk. The bulk case matters because it says up to 200 records can be passed through your code. Say that last part in the interview; it shows you test for more than the number.
12. Can you write Apex directly in production?
No, and this question tests whether you know the development process. Salesforce's anonymous blocks page says the Setup code editors cannot modify Apex in a production org. You develop in a sandbox or Developer Edition org, run the tests, and deploy. The testing page adds that when you deploy Apex to production, each unit test in your org's namespace runs by default. If you want a quick rundown of where to work, see my post on the Developer Console and Web Console.
Questions that are really about judgment
Some interviewers will ask when you would use Apex instead of a flow. The Platform Developer exam guide lists "when to use declarative vs. programmatic methods" as something a candidate knows, so expect it. My answer: use the declarative tool when it meets the requirement, and use Apex when you need logic it cannot express or have to handle large volumes. See my full comparison, Apex vs Flow. And for async options such as queueable and batch, see asynchronous Apex explained.
Mistakes to avoid
- Reciting numbers you are not sure of. Say what a limit protects and where you would check it.
- Describing triggers for one record. Code can receive many records at once.
- Saying 75% is the goal. Salesforce says to cover every use case.
- Claiming you can catch every error. Limit exceptions cannot be caught.
- Never having run the code. Practice each answer in an org so you can describe what you saw.
Cert Lab by Nick Frates
Practicing Apex questions?
The Platform Developer Cert Lab has lessons weighted like the exam, practice questions that explain every option, flashcards and timed practice exams, so you can see which Apex topics you still need to work on.
Start the Cert Lab, $9.99 →Frequently asked questions
What are the most common Apex interview questions?
Collections, SOQL vs SOSL, DML vs Database methods, trigger context and before vs after, exceptions, governor limits, test classes and deployment. The twelve above cover them.
How do I prepare for an Apex interview?
Build a small project in a Developer Edition org with a trigger, a class and a test. Practice each answer out loud with a rule, an example and a trade-off.
What is the difference between a before and an after trigger?
A before trigger fires before records are saved and can change the records in Trigger.new. An after trigger fires after records are saved.
What is the difference between insert and Database.insert?
insert throws an exception if a record fails. Database.insert with a second parameter of false allows partial success and returns result objects.
How much test coverage is required?
At least 75% of your Apex code, with all tests passing, before you can deploy.
Can limit exceptions be caught?
No. Salesforce says the limit exception cannot be caught, and the catch and finally blocks do not run.
Do Apex interviews include live coding?
I cannot say for any company. Prepare for it by writing short snippets, like the ones above, by hand without autocomplete.
Hope this helps!
Best,
Nick


