OrgReady

Salesforce Skills & Readiness

Learning progress is unavailable. Reading and direct practice remain available; completion controls are disabled.

← Back to Salesforce Development

Lesson 5 of 6 · 5–10 minutes including the walkthrough and reflection

Async Apex

Some Salesforce work should not block the user’s save or page action. Async Apex lets you defer work, process larger workloads, schedule work, or handle follow-up processing while giving the user a faster response.

The concept

Async Apex is about choosing the right execution contract. Simple decision framework: Need a normal background job with richer Apex support? → Queueable Apex Need to process a very large number of records in chunks? → Batch Apex Need work to run at a specific time or recurring schedule? → Scheduled Apex Need to understand older code or a simple fire-and-forget method? → Future methods Common tools: Future - Method-based async style. - Developers still encounter it in older orgs. - Useful to understand, but Queueable is often easier to structure for newer designs because it uses a class and can support more complex types and job chaining patterns described by Salesforce. Queueable - Class-based job with an execute method. - Enqueueing returns a job ID. - Good for background work that benefits from clearer structure. Batch - Designed for large data volumes split into batches. - Good when the workload is many records, not just “do this later.” Scheduled Apex - Runs Apex at a scheduled time. - Often used to start recurring cleanup, sync, or batch processes.

Worked example

public class AccountSyncJob implements Queueable {
    private Set<Id> accountIds;

    public AccountSyncJob(Set<Id> accountIds) {
        this.accountIds = accountIds;
    }

    public void execute(QueueableContext context) {
        List<Account> accounts = [
            SELECT Id, Name
            FROM Account
            WHERE Id IN :accountIds
        ];

        // Perform the deferred integration or follow-up work here.
    }
}

// Enqueue from synchronous logic after deciding the work can finish later.
Id jobId = System.enqueueJob(new AccountSyncJob(changedAccountIds));

A good async design answers three project questions: 1. What must finish before the user gets a response? 2. What can safely finish later? 3. How will a developer or admin know whether the later work succeeded? For example, if an Opportunity update needs to notify an external billing system, the user may not need to wait for the callout path to finish during the save. You can record the intent, enqueue work, and track the job or business status. ⚠️ Async is not a magic fix for poor design. If the job still queries inside loops or hides errors, it only moves the problem to a background transaction. Trade-off mindset: - Queueable improves structure for many background jobs. - Batch is for scale and chunking. - Scheduled Apex is for time-based execution. - Future is worth recognizing, especially in existing codebases, but it should not be the automatic choice for new designs.

Common mistake

❌ Common mistake: Making code async because “it hits limits” without changing the data-access pattern. Another mistake: Returning success to the user when you only enqueued a job. Enqueued means accepted for later processing. It does not mean the downstream work has succeeded.

Interview angle

🎯 Interview angle Question: “When would you choose Queueable, Batch, Scheduled Apex, or Future?” Weak answer: “Queueable is better than Future.” Stronger answer: “I choose based on the job’s contract. Queueable is a good fit for structured background work and job tracking. Batch is for large record sets that need chunked processing. Scheduled Apex runs work at a planned time. Future exists and appears in older code, but for many newer designs Queueable gives a clearer class-based model.”

Pause and apply

🧠 Key takeaway: Immediate user need ↓ Deferred work contract ↓ Right async tool ↓ Tracking and failure visibility Try it yourself: 1. A nightly cleanup must run every day at 1 AM. Which async tool fits best? 2. A user save needs a small follow-up job with a job ID for tracking. Which tool would you consider first? 3. A process must update millions of historical records. Why is Batch different from Queueable here? 4. What should the UI say if the system has only enqueued work but not completed it?

Official references

Reviewed 2026-09-15. Examples are illustrative; no code is executed here.

Apply it in practice

Choose the Right Async Apex Tool

Marking a lesson as read records learning activity, not mastery. Practice evidence continues to come from the challenge system.