Plat-Dev-301 practice question 1 of 10

Which use case can be performed only by using asynchronous Apex?

Full set: 160 questions
Answer options
A: Querying tens of thousands of records
B: Making a call to schedule a batch process to complete in the future
C: Calling a web service from an Apex trigger Correct answer
D: Updating a record after the completion of an insert1
Correct Answer:
C. Calling a web service from an Apex trigger
Explanation

Salesforce prohibits making synchronous web service callouts directly from an Apex trigger. This restriction is in place to prevent long-running callouts from blocking database operations. To perform a callout after a DML event, the logic must be executed asynchronously. This is achieved by invoking a method annotated with @future(callout=true) or by enqueuing a Queueable Apex job from the trigger. These asynchronous processes run in a separate transaction, allowing the callout to be made without violating governor limits or platform constraints.

Why Incorrect

A. Querying large datasets can be done synchronously using a SOQL For Loop, which efficiently handles large result sets by batching records and avoiding heap limit errors.
B. Scheduling a future batch process using System.scheduleBatch is an action that can be initiated from a synchronous context, such as an anonymous Apex window or a Visualforce controller.
D. Updating a related record after an insert is a standard use case for an after insert trigger, which operates synchronously within the same transaction as the initial DML operation.

References

1. Apex Developer Guide, "Triggers and Callouts". This section explicitly states, "You can’t make a callout from a trigger." It then recommends using an asynchronous method (e.g., a future method) to perform the callout.

2. Apex Developer Guide, "Future Methods". The documentation details the use of the @future(callout=true) annotation, which is the primary mechanism for making callouts from trigger logic.

Scroll to Top