# What role does asynchronous Apex play in managing high-volume SFS data operations?

**Topic:** Field Service · **Difficulty:** Medium · **Tags:** Field Service, Asynchronous Apex, Performance

Read it on the site: https://www.forcechallenges.com/interview-questions/what-role-does-asynchronous-apex-play-in-managing-high-volume-sfs-data-operations

## Answer

**Basics:** Synchronous Apex has 10,000 ms CPU, 6 MB heap and 100 SOQL; asynchronous gets 60,000 ms CPU, 12 MB heap and 200 SOQL queries per transaction, and Batch splits big data into independent chunks.

**How it works:** Typical SFS cases: a scheduled job that creates work orders or processes appointments in bulk; a batch that updates thousands of Service Appointments; a Queueable that geocodes addresses with callouts; a scheduled job that triggers territory assignment. Each batch execute runs with fresh limits, so millions of records can be handled in chunks. Platform features such as Maintenance Plan work order generation also run in the background.

**Advanced / deep dive:** Choose Batch for large volumes (QueryLocator up to 50 million records), Queueable for chained steps or callouts with object state, scheduled Apex to start them, and Platform Events or Flow for reactive logic. Calls into FSL managed-package scheduling Apex from async may involve callouts, so avoid uncommitted DML before them; verify in package docs. Beware interference with the managed package's own triggers when bulk updating appointments and assigned resources.

**Code / config example:**
```apex
public class StaleApptBatch implements Database.Batchable<SObject> {
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id, Status FROM ServiceAppointment
            WHERE Status = 'None' AND DueDate < TODAY]);
    }
    public void execute(Database.BatchableContext bc, List<ServiceAppointment> scope) {
        for (ServiceAppointment sa : scope) { sa.Status = 'Canceled'; }
        // partial success; failures do not roll back the chunk
        Database.update(scope, false);
    }
    public void finish(Database.BatchableContext bc) {}
}
// Database.executeBatch(new StaleApptBatch(), 200);
```

**Hidden gotchas & must-remember points:**
- Only 5 batch jobs run concurrently; extras wait in the Flex Queue (up to 100 Holding).
- Callouts in batch require Database.AllowsCallouts.
- Updating appointments in bulk can fire managed-package triggers; test with realistic volumes.
- Async executions have a daily shared limit; verify the current figure.
- Do not hard-code status strings if you have custom values; use status categories.

**Best practice:** Use Batch with a modest scope size for bulk SFS changes and keep logic idempotent.

---
Source: ForceChallenges · last updated 2026-11-02
