Salesforce Development Interview Questions & Answers — Part 1 (Apex Essentials)

A compact, practical guide to core Apex concepts and common interview questions for Salesforce developers. Covers collections, triggers, asynchronous patterns, governor limits, and best practices with code examples.

Introduction

This post summarizes essential Apex development concepts frequently asked during Salesforce developer interviews. It includes definitions, practical examples, and actionable best practices for writing scalable, testable code on the Salesforce platform.

Core Concepts

What is Apex?

Apex is a strongly typed, object-oriented language used on the Salesforce platform to implement server-side business logic. It tightly integrates with Salesforce data model (SOQL/SOSL and DML) and enforces governor limits in a multitenant environment.

public class HelloWorld {
    public static void sayHello() {
        System.debug('Hello, Salesforce World!');
    }
}

Collections: List, Set, Map

Use collections to bulkify operations and avoid governor-limit pitfalls.

  • List — ordered, allows duplicates. Good when order matters.
  • Set — unique values, ideal for membership checks and ID deduplication.
  • Map — key-value lookups for fast access and grouping.
// Example: Build a Map from a SOQL result
Map accountMap = new Map(
    [SELECT Id, Name FROM Account WHERE Industry = 'Technology']
);

Triggers and Order of Execution

Understand trigger contexts (Trigger.new, Trigger.old, Trigger.newMap, Trigger.oldMap) and the complete save order — validation, before triggers, after triggers, workflows/flows, and commit. Always bulkify and prefer a single trigger per object with a handler class.

Governor Limits

Governor limits protect the multitenant platform. Common limits include SOQL queries (100 sync/200 async), DML statements (150), heap size, and CPU time. Use the Limits class to instrument and guard logic.

Asynchronous Patterns

When operations exceed synchronous limits or require external callouts, move work to async processing:

  • @future — simple async, pass primitives/IDs, limited to 50 calls/transaction.
  • Queueable — pass complex types/sObjects, returns jobId, supports chaining.
  • Batch Apex — process large volumes (up to millions) in discrete transactions.
@future(callout=true)
public static void sendDataToExternalSystem(Set accountIds) {
    List accounts = [SELECT Id, Name FROM Account WHERE Id IN :accountIds];
    // HTTP callout logic
}

Practical Best Practices

  • Bulkify everything — process collections, not single records.
  • Move SOQL/DML out of loops; use Maps for lookups.
  • Use a trigger handler pattern to keep triggers thin and testable.
  • Prefer Queueable or Batch for long-running or large-volume jobs.
  • Protect against recursion using static variables scoped to the transaction.
  • Write thorough test methods with positive/negative cases and use System.assertEquals to validate behavior.

Code & Testing Tips

Always include unit tests for every public method and trigger path. Use Test.startTest()/Test.stopTest() to test async behavior and assert results with System.assertEquals.

@isTest
static void testHelloWorld() {
    Test.startTest();
    HelloWorld.sayHello();
    Test.stopTest();
    System.assert(true, 'HelloWorld executed');
}

Conclusion — Why this matters

Mastering these Apex fundamentals helps Salesforce developers write reliable, efficient solutions that respect platform constraints. For admins and business users, it means predictable automations, better performance, and easier maintenance. For devs, it improves interview readiness and real-world delivery capability.

Tags: Apex, Triggers, Governor Limits, Async, SOQL