Sub topic 1
Why Integration Patterns Matter
Prerequisites
This chapter assumes you understand Salesforce objects, fields, and records; REST APIs and JSON; basic Apex; and HTTP methods and status codes.
Why integration patterns matter
An integration pattern is a repeatable way for Salesforce to exchange data with another system. The pattern determines when data moves, which system waits, and how failures are handled.
The three patterns in this tutorial solve different problems:
- Request-reply sends a request and waits for an immediate answer.
- Fire-and-forget publishes a message and continues without waiting for processing.
- Batch sync moves many records together, usually on a schedule.
Choosing deliberately reduces timeout risks, duplicate records, and tightly coupled systems.
Synchronous and asynchronous communication
Synchronous communication blocks the caller until the operation finishes. Request-reply is useful when a user or transaction needs an answer, such as checking an invoice status. A slow or unavailable remote system can make the Salesforce transaction fail.
Asynchronous communication separates sending from processing. Fire-and-forget lets Salesforce publish an event while subscribers process it later. Batch sync also separates data movement from normal user transactions. These approaches tolerate delays better, but the sender must handle eventual consistency and delayed errors.
The Salesforce integration toolbox
| Requirement | Salesforce feature | Typical behavior |
|---|---|---|
| Call an external service | Apex callout or REST API | Request-reply |
| Notify several subscribers | Platform Events or Change Data Capture | Fire-and-forget |
| Move large data volumes | Bulk API 2.0 | Batch sync |
The choice also depends on limits, security, retry behavior, and whether the external system needs Salesforce to initiate or receive the exchange.
Authenticating integrations with Named Credentials
A Named Credential stores the endpoint and authentication configuration separately from Apex. This avoids hard-coded hosts, tokens, and secrets. An Apex callout can refer to the credential by name:
public with sharing class InvoiceClient {
public static HttpResponse fetch(String invoiceId) {
HttpRequest request = new HttpRequest();
request.setEndpoint(
'callout:Billing_API/invoices/' +
EncodingUtil.urlEncode(invoiceId, 'UTF-8')
);
request.setMethod('GET');
request.setTimeout(10000);
return new Http().send(request);
}
}The Billing_API Named Credential supplies the base URL and OAuth or other configured authentication. Administrators can change credentials without editing code.
Exercise
An invoice status must appear before a user continues. Which pattern fits best, and why?
Show answer
Request-reply fits because Salesforce must wait for the external system's response.