Sub topic 3
Limits That Shape Your Salesforce Integration Design
Assume you know Salesforce objects, basic Apex, REST, JSON, and HTTP status codes. Integration limits affect which pattern is safe. Design around them before writing code.
Limits That Shape Your Design
Synchronous Apex has governor limits, including limits on callouts, CPU time, and database operations within one transaction. A request-reply callout can also time out while the external system is processing. Keep the response path short and move slow work to asynchronous processing.
Salesforce APIs have daily request limits. Bulk API 2.0 reduces request overhead for large data sets. Platform events have publishing and delivery limits, and subscribers must handle messages that arrive later or more than once.
| Requirement | Usually suitable | Main constraint |
|---|---|---|
| Need an immediate answer | REST API or Apex callout | Timeout and transaction limits |
| Notify several systems | Platform event | Delivery, replay, and subscriber handling |
| Move many records | Bulk API 2.0 | Job state and batch monitoring |
Making Repeated Messages Safe with External IDs
An operation is idempotent when repeating it produces the same result as performing it once. Use an external ID field as the stable identifier owned by the source system. A REST upsert or Bulk API 2.0 upsert can then update an existing record instead of creating a duplicate.
Store a source message ID or request ID when possible. Reject or safely ignore a message that has already been processed.
Handling Failures, Retries, and Replay
Retry temporary failures such as HTTP 429 or 503 with exponential backoff. Do not retry permanent errors such as invalid fields or failed authentication without correcting the cause. Set a maximum retry count and send exhausted messages to a review queue.
For platform events, subscribers should track replay positions and recover from disconnects. Make processing idempotent because replay can deliver an event again.
Choosing the Right Pattern
Choose request-reply when the user or transaction needs a prompt result. Choose fire-and-forget when the publisher should not wait and multiple consumers may react independently. Choose batch sync for high-volume transfers where delayed processing is acceptable.
Monitoring and Operating Integrations
Monitor API usage, failed callouts, event delivery, replay gaps, Bulk API job state, retry counts, and dead-letter records. Include correlation IDs in logs so one business operation can be traced across systems.
Exercise
Which pattern fits a nightly transfer of two million records, and how should duplicates be prevented?
Show answer
Use Bulk API 2.0 with an external ID upsert. Track the job and retry temporary failures without creating new records for repeated source IDs.