Salesforce-Platform-Developer-II Practice Test
202 Questions
A Visualforce page needs to make a callout to get billing information and tax information from two different REST endpoints. The information needs to be displayed to the user at the same time and the return value of the billing information contains the input for the tax information callout. Each endpoint might take up to two minutes to process. How should a developer implement the callouts?
A. An HTTP REST callout for the billing callout and a Continuation for the tax callout
B. A Continuation for both the billing callout and the tax callout
C. An HTTP REST callout for both the billing callout and the tax callout
D. A Continuation for the billing callout and an HTTP REST callout for the tax callout
Explanation:
To determine the best approach, let’s break down the scenario:
➞ A Visualforce page needs to make two REST callouts.
➞ The tax information callout depends on the result of the billing callout (chained callouts).
➞ Each callout may take up to two minutes — which exceeds Apex's standard 10-second limit for synchronous callouts.
➞ The user must see both results at the same time.
In such cases, standard HTTP callouts won't work due to timeouts. You need a way to manage long-running processes—this is exactly what Continuations are built for in Visualforce.
✅ Correct Answer: B. A Continuation for both the billing callout and the tax callout
The Continuation class allows Apex to perform asynchronous callouts that don’t block server threads and support timeouts up to 120 seconds per callout. Since both billing and tax endpoints may take up to 2 minutes, standard synchronous callouts will fail, and using Continuation ensures the Visualforce page remains responsive.
Here, even though the tax callout depends on billing’s result, you can structure the logic such that:
1. The first Continuation callout fetches billing data.
2. Once billing data is available, a second Continuation callout is made using the required input.
3. The final response is returned once both callouts complete.
This can be achieved using chained Continuation callouts, where the second call is triggered within the callback method of the first.
🔗 Reference: Salesforce Developer Guide – Asynchronous Callouts Using Continuations
❌ A. An HTTP REST callout for the billing callout and a Continuation for the tax callout
This option fails because billing is the first call, and if it takes longer than 10 seconds, a synchronous HTTP callout will time out. So this won't work even before reaching the second call.
❌ C. An HTTP REST callout for both the billing callout and the tax callout
This is completely invalid. Standard synchronous Apex callouts only support up to 10 seconds, and both endpoints can take up to 2 minutes. The callouts will timeout and fail.
❌ D. A Continuation for the billing callout and an HTTP REST callout for the tax callout
Even though the billing callout is made using Continuation, the second call (tax) is still synchronous and may timeout due to the long processing time. This hybrid strategy is not reliable for long-running endpoints.
✅ Final Verdict:
B. A Continuation for both the billing callout and the tax callout is the correct and most efficient approach. It adheres to the governor limits, handles long-running callouts gracefully, and fits the dependency pattern between the two REST endpoints.
Salesforce-Platform-Developer-II Practice-Test - Home | Previous |
Page 9 out of 202 Pages |