APEX-Q06โ˜… Must-prepareScenario AdvancedApex & triggers#integration#apex#async-apex

An integration queueable fails intermittently when ERP times out, and failures go unnoticed. How do you make it robust?

Your confidence:Not rated

Model answer

  1. Attach a Finalizer in execute(). It runs even after uncatchable failures, inspects ParentJobResult, and decides what to do.
  2. Retry with back-off: re-enqueue with System.enqueueJob(job, delayMinutes) and an attempt counter; stop after N attempts.
  3. Idempotency: send an idempotency key or external ID so ERP ignores duplicates; check status before resubmitting.
  4. Avoid duplicate jobs: set an AsyncOptions duplicate signature per logical unit (for example per order).
  5. Log and alert: write failures to an integration log object (or publish a platform event that a logging subscriber stores), and alert support when the final attempt fails.
  6. Circuit breaker: if ERP is down, stop enqueuing new jobs for a period (a custom metadata or custom setting flag), and queue work for later replay.
  7. Replay: a small batch or admin action re-submits logged failures once ERP is back.
  8. Timeouts and Named Credentials: set explicit callout timeouts, and keep endpoints and auth in Named Credentials and External Credentials.

โœ” Key points to hit

โœ– Red-flag answers

  • Infinite retries
  • Retrying non-idempotent calls
  • Silent catch blocks
  • Hardcoded endpoints

โ†ช Follow-ups

Why not just catch the exception in execute()?

Some failures, such as limit exceptions or timeouts that exhaust CPU, can't be caught. A Finalizer runs after the job ends regardless, so it's the reliable place for recovery logic.

Would platform events help here?

Yes, for decoupling: the trigger publishes an 'order ready' event and a subscriber handles submission with its own retries (EventBus.RetryableException). Logging via events also survives rollbacks if published immediately.