What are @future methods and when do you use them?
Suggested answer
@future methods run asynchronously in a separate thread, useful for:
1. Callouts from triggers: Triggers cannot make synchronous callouts. Annotate with @future(callout=true).
2. Mixed DML workaround: Mixing DML on setup and non-setup objects in one transaction causes a Mixed DML error. Moving one DML operation to a @future method resolves this. Limitations:
3. Only primitive parameters (no sObjects or custom types — pass IDs and re-query inside).
4. Cannot be called from Batch Apex.
5. Maximum 50 @future calls per transaction.
6. Cannot chain @future methods (call another @future from within @future). For complex async scenarios, use Queueable Apex instead.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.