ApexAdvancedcalloutsintegrationretrytimeout
Handle callouts, timeouts, and retry patterns in Apex integrations
Real World Scenario
Payment gateway callouts from trigger cause failures when API latency spikes; users see DML rollback on unrelated records.
Expected Answer
• Never synchronous callout from trigger on user transaction—use Queueable or Platform Event subscriber
• Set explicit timeout values; handle HttpResponse status codes with typed exceptions
• Implement retry with exponential backoff in async jobs for transient 5xx errors
• Idempotency keys on payment APIs preventing duplicate charges on retry
• Store callout request/response in custom log object for support debugging
• Circuit breaker pattern pausing callouts when error rate exceeds threshold
• Named Credentials for URL and auth centralization across environments
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Direct answer: Never synchronous callout from trigger on user transaction—use Queueable or Platform Event subscriber Also consider: Set explicit timeout values; handle HttpResponse status codes with typed exceptions In practice: Implement retry with exponential backoff in async jobs for transient 5xx errors Optimize for scale and operational observability.
Architect Perspective
User-facing DML must not depend on external API availability—decouple with async and compensating transactions.