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
- Attach a Finalizer in
execute(). It runs even after uncatchable failures, inspectsParentJobResult, and decides what to do. - Retry with back-off: re-enqueue with
System.enqueueJob(job, delayMinutes)and an attempt counter; stop after N attempts. - Idempotency: send an idempotency key or external ID so ERP ignores duplicates; check status before resubmitting.
- Avoid duplicate jobs: set an
AsyncOptionsduplicate signature per logical unit (for example per order). - 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.
- 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.
- Replay: a small batch or admin action re-submits logged failures once ERP is back.
- 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.