Overview of Salesforce integration
Integration work rests on two foundations: the Salesforce platform limits, and the communication protocols the rest of the industry has settled on. Whether you consume an external service or expose Salesforce data, the architecture has to put security, scalability and idempotency first.
Core integration patterns
Identify the pattern that fits the requirement before you write code:
- Request-reply. Synchronous, where the client waits for a response, as with standard REST or SOAP calls.
- Fire-and-forget. Asynchronous, through Platform Events or Change Data Capture (CDC).
- Batch data sync. Large volumes moved with Bulk API 2.0 or ETL and middleware tools.
- Remote call-in. External systems querying Salesforce through the Force.com REST or SOAP APIs.
Technical implementation steps
1. Master authentication
Credentials do not belong in code. Use OAuth 2.0 flows, specifically:
- JWT Bearer Token Flow, for server-to-server communication.
- Client Credentials Flow, for background processes with no user in the loop.
2. Standardize API usage
Callouts from Apex go through the HttpRequest and HttpResponse classes. Handle the HTTP status codes properly rather than assuming a response came back clean.
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:My_Named_Credential/services/data/v59.0/query?q=SELECT+Id+FROM+Account');
req.setMethod('GET');
HttpResponse res = h.send(req);
if (res.getStatusCode() == 200) {
System.debug(res.getBody());
} else {
// Log error and handle exceptions
}
3. Handle governor limits
Salesforce caps callouts hard, at 100 per transaction for example. Move anything long-running out of the main transaction with the @future(callout=true) annotation or Queueable Apex.
Best practices for architects
- Named Credentials keep endpoints and authentication settings out of your code.
- Idempotency means processing the same message twice does not leave you with duplicate records.
- Log integration failures to a dedicated object or platform event, so there is something to audit later.
Leave a Comment