OBLYTECH Logo
OBLYTECH Logo

Continuation Callouts for Slow External Lookups During a Page Request

A continuation callout lets Apex start several slow external requests from a synchronous transaction and wait for them in parallel, which shortens the total wait. Choose it when the user needs the answer before the page can continue. When the result can arrive later, an asynchronous job such as Queueable Apex is usually the better fit.

How a continuation callout fits into a synchronous request

A synchronous request runs its steps in order. If a page needs three external lookups and each one is called after the previous reply arrives, the user waits for all three in sequence. A continuation callout changes that order. Apex starts the external requests from inside the synchronous transaction, the platform runs them side by side, and the transaction resumes in a callback once the replies come back. The wait is then driven by the slowest reply, not by the sum of all of them.

The pattern fits a read the user is actively waiting on, such as a shipping estimate, a credit status or a price pulled from a partner system while the screen is open. It does not help when there is a single slow lookup, and it does not help when one lookup needs the output of another. A dependent lookup has to run after its input exists, and adding parallelism does not change that order.

Before you start, sketch the flow on paper. Mark each lookup, the fields it needs and the fields it returns. Any arrow from one lookup into another is a dependency that rules that pair out for parallel calls.

Signs that lookups are independent

Independent lookups share no inputs with each other. Each one can be built from data already on the record or from the user’s entry. If two calls need a value from the same reply, combine them into one call, or sequence them and accept the longer wait. Keep the set small. A handful of parallel lookups is easier to test, debug and explain to the user than a long fan-out, and each extra service adds another failure path to handle.

Choosing between a continuation callout and an asynchronous job

The first question is whether the user needs the answer before the next step. If they do, use synchronous processing. If they do not, an asynchronous job is usually the better design. A common example is sending an order to a warehouse system. The user can finish the order and move on before the warehouse confirms receipt, so the confirmation can arrive later and update the record.

Asynchronous work runs in its own threads, so users can keep working while it runs, and it has higher governor limits than synchronous work. Async capacity is still finite and depends on licensing, so it is no substitute for planning around volume.

When Queueable Apex is the better fit

Queueable Apex suits long-running database operations and external callouts. It supports job IDs, non-primitive types and chaining. A save can finish quickly while the follow-on updates run in a chain of transactions, each one picking up where the last one stopped. Use it when the lookup result changes records that the user does not need to see at once.

When Batch Apex is the better fit

Batch Apex is built for very large record sets, such as millions of records. It processes records in chunks, which suits data cleansing and nightly rollups. A single lookup for one user during a page request is rarely the right shape for it. If the work touches thousands of records, plan the chunk size and the schedule first, and do not start that work from inside a page request.

For help planning this work, see Salesforce implementation.

Setting up parallel lookups inside a synchronous transaction

Build the work in this order so that each step can be tested on its own.

  1. List each external service the page needs, the fields it returns and a rough sense of how long it usually takes to reply.
  2. Confirm that no lookup depends on another lookup’s reply.
  3. Prepare each request before the first callout starts, so the calling code has nothing left to do but send them.
  4. Write the callback that runs when the replies return. It should match each reply to its request and store the result in the right place.
  5. Decide what the page shows for a lookup that fails or arrives late, such as a placeholder value or a short message beside that section.
  6. Test with each service slowed down on purpose, to confirm the total wait stays within what the page can tolerate.

Budget developer time for this work. The pattern requires Apex skills, including handling callouts, processing responses and covering the failure paths. An administrator can configure the page layout and the fields it shows, but the callouts and the callback belong to a developer.

Callouts from triggers and after data changes

Callouts made from a trigger, or after a DML operation in the same transaction, must run in a future or queueable method. A callout in a trigger also holds the database connection open for the lifetime of the callout, so a slow lookup there ties up that connection for the whole wait.

This changes the design when a record save must trigger an external lookup. The synchronous part saves the record and returns. A queueable job then makes the lookup and writes the result back. The user sees the save complete at once, and the lookup result appears when the job finishes. Before you add a callout to a flow, review the step order on the Salesforce automation workflows page, because the order of steps decides which transaction a callout lands in.

Mixed updates need the same care. When a record-triggered flow updates one object and then writes to an external object through Salesforce Connect, add a pause element between the two steps, set to zero seconds, to avoid mixed-transaction errors.

Limits and delays to plan for in asynchronous work

Asynchronous processing has no service-level agreement, so a queued job can start later than expected, and the wait grows when the org is busy. Plan the screen for that delay. Show a pending status on the record, or add a short note that the result will appear later, instead of an empty field that looks broken.

Each asynchronous tool has its own governor limits. Licensing can also raise some of these limits, so check what your org has before you commit. Before you commit to a pattern, estimate the daily count of callouts and jobs, then compare that figure with the limits that apply. The API call budget checklist for integration architects walks through how to build that estimate before the design is locked.

Governor limits apply inside each transaction, whether it runs synchronously or asynchronously. Admins who add a callout to a flow or a trigger should know the per-transaction ceilings first. The governor limits for admins guide covers the limits that come up in configuration work. Check each figure against your own org and release, because limits can change between releases.

Testing and monitoring a lookup design after launch

Test in a sandbox that mirrors the external service’s response times, not just its data. A lookup that is quick in testing can slow down in production at peak hours. Record the wait for each lookup, and compare the total against the wait the page can tolerate.

After launch, watch for three patterns: replies that arrive late, lookups that fail more often than expected, and asynchronous jobs that sit in the queue for a long time. Each one points to a different fix. Late replies usually call for a timeout plan or a placeholder. Frequent failures call for clearer error messages and a retry path. Long queues call for fewer jobs or a schedule that spreads the work out.

Data integration decisions also shape the design. Where the external system holds large data sets or runs nightly syncs, the bulk and batch patterns apply instead of page-level lookups. For that side of the work, see data migration and integration.

Questions about parallel lookups and asynchronous fallbacks

Can a continuation callout replace a queueable job for all external calls?

No. A continuation callout makes sense when the user waits on the reply. Calls that the user does not wait on, or that run against many records at once, belong in an asynchronous job.

What should the page show while a slow lookup is still pending?

Give that section a labeled pending state so the user knows a value is coming. If the reply does not arrive in time, a short message saying the data is not yet available is clearer than a blank field.

How should a failed asynchronous job be reported to users and admins?

Write the failure to a field or a log that someone can see, and give an admin a way to rerun the job. Users should see a status that says the work is pending or needs attention, not a silent gap. Check the job status before you assume the work finished.

Does Outbound Messaging work like a queued lookup?

Not for lookups. Outbound Messaging is a fire-and-forget option: messages are sent without a reply, and any that remain undelivered after 24 hours are dropped. That makes it suited to notifications, not to a reply the page needs in order to finish.