ApexBeginnerfutureasync
What are future methods and when use them?
Real World Scenario
A trigger must call an external API but callouts cannot run with pending DML. You mention @future.
Expected Answer
• @future methods run asynchronously in a separate transaction after the calling one commits
• Use when you need callouts after DML or to offload non-critical work
• Future methods must be static void with callout=true flag when calling external systems
• Cannot pass sObjects to future—pass IDs only
• Newer patterns include Queueable and Platform Events for more flexibility
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Salesforce forbids uncommitted work pending with callouts in one sync transaction. Order must be callout then DML, or use async.
Architect Perspective
Callout + DML ordering is a favorite trap—know sync rules before async patterns.