the Apex Connector Framework
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Module 4 of 6 in the chapter Data Connectivity and Virtualization, chapter 19 of the Integration Architect course. Each module stands on its own. Previous: Reaching a Database, and Everything Else · Next: A Component That Reads Live
The question this module answers: When the other system speaks none of Salesforce Connect’s languages, how do you write the adapter yourself, and what do you sign up for when you do?
A Little Bit of Apex
Section titled “A Little Bit of Apex”In class, after OData and cross-org, I tell people there’s more: you can write a little bit of Apex, pull the data yourself, and it can look just like Salesforce Connect.
That’s the custom adapter. Salesforce’s guide describes it this way: “Use the Apex Connector Framework to develop a custom adapter for Salesforce Connect. The custom adapter can retrieve data from external systems and synthesize data locally” (Salesforce Connect (opens in a new tab), Apex Developer Guide, checked 2026-11-21).
You reach for it when the system has an API, but not one any adapter speaks: a REST API that isn’t OData, with its own way to filter and page. Everything the user sees is the same as with any other adapter: external objects, list views, related lists, lookups and search. The difference is that the translation, from what Salesforce asks to what the API understands, is your code.
One licensing point before you start: “The DataSource.Connection class requires a Salesforce Connect add-on license” (Get Started with the Apex Connector Framework (opens in a new tab), checked 2026-11-21). A custom adapter is still Salesforce Connect (chapter 16 module 5).
Two Classes
Section titled “Two Classes”To build one, you “create two Apex classes: one that extends the DataSource.Connection class, and one that extends the DataSource.Provider class.”
The provider says what the adapter can do. It “informs Salesforce of the authentication and functional capabilities that are supported by or required to connect to the external system”: whether it signs in, and how, and whether it can answer queries, searches and saves. For signing in, “Salesforce can provide the authentication credentials from the external data source definition or users’ personal settings”, so the secrets stay in Salesforce’s credential settings, not in your code (chapter 9).
The connection does the work. Each of its methods answers something a person does in Salesforce.
| When someone… | Salesforce calls | It must… |
|---|---|---|
| Clicks Validate and Sync on the data source | sync() | Describe the tables and columns, so Salesforce can create the external objects |
| Opens a list view, a related list or a record | query() | Fetch the rows that match, sorted and paged |
| Searches | search() | Find rows that match the search text |
| Saves or deletes a record, if writing is on | upsertRows() and deleteRows() | Send the change to the other system |
In the guide’s words, sync() “is invoked when an administrator clicks the Validate and Sync button”, and query() “is invoked when a SOQL query is executed on an external object. A SOQL query is automatically generated and executed when a user opens an external object’s list view or detail page” (Create a Sample DataSource.Connection Class (opens in a new tab), checked 2026-11-21).
It’s the same conversation as module 2’s OData, with you in the middle. Salesforce asks for “the order details for this order, these columns, sorted, first page”, and your query() turns that into whatever the API understands.
Do the Work on the Other Side
Section titled “Do the Work on the Other Side”Here’s the mistake the guide warns about, and it’s an easy one to make.
The framework comes with a helper, DataSource.QueryUtils, that filters and sorts rows inside Salesforce. It’s handy in a first test. But the guide is direct: its methods “aren’t supported for use in production environments that use callouts to retrieve data from external systems. Complete the filtering and sorting on the external system before sending the query results to Salesforce.”
Think about why. If your adapter asks the API for every order detail and filters them in Apex, every related list downloads the whole table. It works with fifty rows in a test. It falls over with five million in production.
So the adapter’s real job is translation: turn Salesforce’s filter, sort and page into the API’s own filter, sort and page, and ask for only what the screen needs. Everything module 2 asked of an OData producer, your adapter now asks of the API, in the API’s language.
What the Guide Warns About
Section titled “What the Guide Warns About”The guide’s considerations page is short, and worth reading in full before you build (Considerations for the Apex Connector Framework (opens in a new tab), checked 2026-11-21). Four of its points matter most for design.
- “DML operations aren’t allowed in the Apex code that comprises the custom adapter.” The adapter reads and writes the other system. It can’t save Salesforce records while it does.
- “Make sure that you understand the limits of the external system’s APIs. For example, some external systems accept only requests for up to 40 rows.” Your adapter has to page within the API’s limits, not Salesforce’s.
- Data types. A Double “loses precision beyond 18 significant digits”, and a String over 255 characters becomes a long text area. Decide the field types on purpose in
sync(). - Resave the provider whenever you change the connection class, or the adapter disappears from the data source’s list.
And it’s code, so everything chapter 9 asked of a callout applies: a named credential, timeouts, errors that tell the user something useful, and tests. The guide has pages on testing custom adapters with mock queries. Use them.
Adapter, Component or Copy?
Section titled “Adapter, Component or Copy?”So when is a custom adapter the right choice?
When you want the data to behave like an object: in list views, related lists, lookups, global search, reports and flows, with admins able to put it on page layouts. In class I put the trade simply: with Salesforce Connect, your admins and your visual programmers can maintain it, and external objects can go more places than a custom component can.
But you own the code. Every new field in the other system means a change to sync() and query(), a test and a deployment. When the data doesn’t fit rows and columns at all, a component that reads it live may be simpler (module 5). Data Architect chapter 14 compares the two from the page’s side, in Salesforce Connect or a Component?. And when Salesforce has to act on the data, neither is right: copy it.
Test knowledge. Know that when no standard Salesforce Connect adapter fits, a custom adapter can be written in Apex with the Apex Connector Framework, extending
DataSource.ConnectionandDataSource.Provider, and that the result is ordinary external objects. Expect a scenario with a proprietary REST API and a need for real-time access without copying: the answer is Salesforce Connect with a custom adapter.
Beyond the exam: what AI changes. Give an AI the other system’s API description and this module’s two classes, and it will write a working adapter in minutes. Read what it wrote for one thing first: whether it filters and sorts on the other side, or downloads everything and uses
QueryUtils. The second one passes every test with sample data and fails in production. Then test it against the real API’s paging limits.
What an Architect Decides Here
Section titled “What an Architect Decides Here”- Whether a custom adapter is the right tool: the data should behave like an object, and no standard adapter speaks the API.
- Who owns the code, its tests and its changes when the other system changes.
- How it translates: filtering, sorting and paging done by the other system, within that API’s limits.
- How it signs in: through Salesforce’s credential settings, never in the code.
- Which field types
sync()creates, on purpose.
Explore
Section titled “Explore”- Get Started with the Apex Connector Framework (opens in a new tab), Apex Developer Guide (checked 2026-11-26): the two classes, with a sample.
- Considerations for the Apex Connector Framework (opens in a new tab), Apex Developer Guide (checked 2026-11-26).
- Salesforce Connect (opens in a new tab), Apex Developer Guide (checked 2026-11-26): the Apex Connector Framework.
- Create a Sample DataSource.Connection Class (opens in a new tab), Apex Developer Guide (checked 2026-11-26): the first class of your own adapter.
- What OData Is: module 2, the same conversation when the system speaks OData.
