A production-ready Apex framework for HTTP API integrations in Salesforce—features a fluent Builder API, multiple authentication methods, a testing mock library, and production-ready tools like timeouts and retries.
What is the Salesforce Integration Framework?
The Salesforce Integration Framework is a unified, production-ready Apex library that simplifies HTTP API integrations. It provides a fluent Builder-pattern API for all HTTP methods, supports multiple authentication methods (Named Credentials, Bearer Token, Basic Auth, API Key), flexible content types (JSON, XML, form, multipart), and includes a comprehensive testing mock library.
Key features
- Universal HTTP support: GET, POST, PUT, PATCH, DELETE
- Multiple authentication options and secure practices (Named Credentials recommended)
- Builder pattern for readable, chainable requests
- Built-in response parsing (JSON/XML), header access, and status checking
- Complete testing library with request capture and verification
- Production-ready capabilities: timeouts, compression, retries, and error handling
Quick installation
Install the unmanaged package for Sandbox or Production using the following URLs:
- Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04tgK0000003CXh
- Production: https://login.salesforce.com/packaging/installPackage.apexp?p0=04tgK0000003CXh
Before vs After (code example)
Traditional Apex HttpRequest requires verbose setup and manual error handling. The framework reduces boilerplate and makes code more readable.
// Before HttpRequest req = new HttpRequest(); req.setEndpoint('https://api.example.com/users'); req.setMethod('POST'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'Bearer ' + token); req.setBody(JSON.serialize(userData)); req.setTimeout(30000); Http http = new Http(); HttpResponse res = http.send(req); if (res.getStatusCode() == 200) { Mapresult = (Map ) JSON.deserializeUntyped(res.getBody()); // Process result } else { // Manual error handling } // After - using the Integration Framework IntegrationResponse response = IntegrationFramework.newRequest() .method(HttpMethod.POST) .endpoint('/api/users') .withNamedCredential('My_API') .jsonBody(userData) .execute(); if (response.isSuccess()) { Map result = response.getBodyAsMap(); // Process result }
Authentication methods
Use Named Credentials for production. The framework also supports Bearer tokens, Basic Auth, and API keys.
Response handling and testing
The framework provides helpers for:
- Checking status codes: isSuccess(), isClientError(), isServerError()
- Parsing bodies: getBodyAsMap(), getBodyAsXml(), raw body access
- Accessing headers for pagination and rate limiting
- Mocking HTTP callouts with IntegrationMockLibrary for unit tests
@isTest public class MyIntegrationTest { @isTest static void testSuccessfulCall() { IntegrationMockLibrary.MockHttpCallout mock = new IntegrationMockLibrary.MockHttpCallout(); MapmockData = new Map {'id' => '123', 'name' => 'Test'}; mock.setResponse('callout:My_API/api/users', IntegrationMockLibrary.jsonSuccessResponse(mockData)); Test.setMock(HttpCalloutMock.class, mock); Test.startTest(); IntegrationResponse response = IntegrationFramework.get('My_API', '/api/users', true); Test.stopTest(); System.assert(response.isSuccess()); Map data = response.getBodyAsMap(); System.assertEquals('123', data.get('id')); } }
Best practices & recommendations
- Security: prefer Named Credentials; store secrets in Custom Settings or Custom Metadata; never hardcode secrets
- Performance: set sane timeouts, enable compression for large payloads, and use pagination for large datasets
- Testing: write unit tests with the provided mock library and verify request details
- Error handling: always check status, implement retry logic for transient errors, and log failures for monitoring
How teams typically use it
Common patterns include service classes that encapsulate API logic, trigger handler patterns for async callouts, batch processing for bulk syncs, and queueable/future methods for background work.
Conclusion
The Salesforce Integration Framework standardizes how teams build and test HTTP integrations in Apex. For Salesforce admins, developers, and architects this means faster development, more consistent code, and safer, testable integrations across the org.
Why this matters for different roles
- Admins: Easier to configure integrations via Named Credentials and fewer surprises in production.
- Developers: Less boilerplate, cleaner code, easier unit testing, and consistent patterns across projects.
- Business users: Faster time-to-market for integrations and more reliable data flows between systems.
Leave a Reply