Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating a simplified Apex HTTP integrations framework for connecting to external APIs.
Integration

Salesforce Integration Framework — Simplify HTTP API Integrations

A production-ready Apex framework for HTTP API integrations in Salesforce: a fluent Builder API, several auth methods, a mock library for tests, and the timeouts and retries production work needs.

The short answer

The Salesforce Integration Framework is an Apex library that wraps HTTP callouts in a fluent builder pattern. It supports several authentication protocols, parses responses, handles errors and retries, and ships a mock library for unit tests.

Key takeaways Build HTTP callouts with a chainable builder pattern that cuts boilerplate across GET, POST, PUT, PATCH, and DELETE. Authenticate with Named Credentials in production, and fall back to Bearer tokens, Basic Auth, or API keys where you have to. Check callout results with the built-in status helpers and parse bodies into maps or XML without writing that code yourself. Stub endpoint responses in unit tests with the framework's IntegrationMockLibrary class. Set request timeouts, turn on payload compression, and add retry logic so transient failures do not break the integration.

An Apex framework for HTTP API integrations in Salesforce, with a fluent Builder API, several authentication methods, a testing mock library, and the things production work needs anyway: timeouts and retries.

What is the Salesforce Integration Framework?

The Salesforce Integration Framework is a production-ready Apex library for HTTP API integrations. It has a fluent Builder-pattern API covering all HTTP methods, supports several authentication methods (Named Credentials, Bearer Token, Basic Auth, API Key) and content types (JSON, XML, form, multipart), and ships with a testing mock library.

Features

  • All the HTTP methods: GET, POST, PUT, PATCH, DELETE
  • Several authentication options, with Named Credentials recommended
  • A builder pattern for readable, chainable requests
  • Response parsing (JSON/XML), header access, and status checking built in
  • A testing library with request capture and verification
  • Timeouts, compression, retries, and error handling for production

Quick installation

Install the unmanaged package for Sandbox or Production using the following URLs:

Before vs After (code example)

A plain Apex HttpRequest takes a lot of setup lines and leaves the error handling to you. The framework cuts the boilerplate, and the result reads better.

// 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) { Map result = (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 in production. The framework also handles Bearer tokens, Basic Auth, and API keys.

Response handling and testing

The framework has 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(); Map mockData = 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, turn on compression for large payloads, and page through large datasets
  • Testing: write unit tests with the mock library and verify the request details
  • Error handling: check the status every time, retry transient errors, and log failures so monitoring picks them up

How teams typically use it

Common patterns: service classes that hold the API logic, trigger handler patterns for async callouts, batch processing for bulk syncs, and queueable or future methods for background work.

Conclusion

The Salesforce Integration Framework standardizes how a team builds and tests HTTP integrations in Apex, which mostly shows up as more consistent code and integrations you can actually test.

Admins get integrations that are easier to configure through Named Credentials, with fewer surprises in production. Developers write less boilerplate and keep the same patterns across projects, and unit tests stop being the hard part. Business users see integrations land sooner and data flows that break less often.

Frequently asked questions

What is the Salesforce Integration Framework?

It is an unmanaged Apex library that standardizes HTTP API integrations in Salesforce. It gives you a fluent builder API, handles several authentication methods and content types, and has built-in tools for response parsing, retries, and unit test mocking.

Which authentication methods are supported by the framework?

Named Credentials are the recommended option for production environments. The framework also handles Bearer tokens, Basic Auth, and API keys when you need a different authentication method.

How do you mock HTTP callouts with the Integration Framework?

Create an IntegrationMockLibrary.MockHttpCallout in your test method, map an endpoint to a mock response with a helper such as jsonSuccessResponse(), then register it with Test.setMock(HttpCalloutMock.class, mock).

How do you parse API responses using the framework?

The response object has status check methods: isSuccess(), isClientError(), and isServerError(). To get at the data, use helpers such as getBodyAsMap() and getBodyAsXml().

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment