Sub topic 3
Choosing an adapter
This chapter helps you pick the Salesforce Connect adapter that fits a given external system. It assumes you know what Salesforce Connect and external objects are, how to read an OData service document, and how to navigate Setup. Basic Apex helps for the custom adapter section.
What an adapter does
A Salesforce Connect adapter is the piece that translates between Salesforce and an external system. When a user opens an external object record, or code runs a SOQL query against one, Salesforce hands the request to the adapter. The adapter turns it into a call the external system understands, sends it, and maps the response back into rows and fields.
You choose the adapter as the Type of the external data source. That choice decides four things:
- Which protocol the external system must speak.
- How the external schema is discovered during Validate and Sync.
- Which operations (read, write, search) are possible.
- How much work you have to do, and how much of it happens in Apex or in the external system.
Pick the adapter before anything else. Changing it later usually means rebuilding the data source and regenerating the external objects.
The four adapter types
| Adapter | External system must be | Schema discovery | Typical use |
|---|---|---|---|
| OData 2.0 | An OData 2.0 producer | Reads the service `$metadata` document | Existing ERP or web services that already expose OData 2.0 |
| OData 4.0 | An OData 4.0 producer | Reads the service `$metadata` document | New or modern services that expose OData 4.0 |
| Cross-org | Another Salesforce org | Reads the other org's objects | Sharing records between orgs without copying them |
| Custom (Apex) | Anything you can call from Apex | Your `sync()` method | Systems with no OData endpoint, such as a plain REST API |
OData 2.0 and OData 4.0
OData is a REST-style protocol with a standard way to describe data ($metadata) and a standard query syntax ($filter, $orderby, $top, $skip). Salesforce translates SOQL clauses into those query options, so the external system does the filtering and sorting.
Use an OData adapter when the external system already publishes an OData endpoint. You write no code, and Validate and Sync builds the external objects from the metadata.
Choose the version that the endpoint implements. The two versions are not interchangeable, because the adapters parse different metadata and expect different payloads. If a service offers both, prefer 4.0 for new work. Use 2.0 when the service only offers 2.0, which is common with older enterprise products.
Check the endpoint before you configure anything. This request should return XML describing entity types and properties:
curl -s -u "$ODATA_USER:$ODATA_PASSWORD" \
'https://example.com/odata.svc/$metadata' | head -n 30Look at the result for three things:
- Each entity set you want to expose has a key. The key becomes the ExternalId.
- The property types are ones Salesforce can map. Unsupported types are skipped or mapped to text.
- The service supports server-side filtering and paging. Without it, large tables are slow.
The OData adapters expose settings that affect behavior. Review these on the data source: the response format (2.0 offers a choice between Atom and JSON), server-driven paging, whether to request row counts, whether the data source can be written to, and whether to include the external objects in Salesforce searches. Exact option names change between releases, so check the data source page in your org.
Cross-org adapter
The cross-org adapter connects one Salesforce org to another using the Salesforce REST API. The org that holds the data is the provider org. The org that shows the data is the subscriber org.
Use it when the data already lives in Salesforce but you don't want to duplicate it. The setup differs from OData in these ways:
- You don't need an OData endpoint. The adapter reads the provider org's object metadata directly.
- Authentication uses a named credential, with a user in the provider org whose permissions decide what the subscriber can see.
- The provider's field-level security and sharing apply to the integration user, not to each subscriber user.
Because every subscriber user reads through one integration identity (with a shared named credential), a user in the subscriber org may see provider records they could not see directly. Give the integration user the narrowest permissions that still work. Alternatively, use a per-user authentication setup, so each user's own provider-org access applies.
Custom adapter
When the external system speaks neither OData nor Salesforce REST, write a custom adapter with the Apex Connector Framework. You extend two classes, DataSource.Provider and DataSource.Connection. The provider declares the authentication methods and capabilities the adapter supports. The connection describes the schema in sync() and returns rows in query(). A later chapter builds one in full.
The costs are real:
- You write and maintain Apex, including tests.
- The callouts in your code count against Apex governor limits.
- You decide how to translate filters, sorting, and paging.
DataSource.QueryUtils.processcan apply them in memory, but that means fetching all rows first, which doesn't scale. - Each capability you want (queries, search, inserts, updates, deletes) must be implemented and declared.
Use a custom adapter when there is no other reasonable path, or when you need logic that no standard adapter offers. Examples are combining two back-end calls into one external object, or shaping a response that doesn't match any standard model.
Choosing: a decision path
Start from what the external system can do today, not from what you would like it to do.
Work through these criteria in order:
- Is the system a Salesforce org? Use the cross-org adapter. It is the simplest option and needs no external service.
- Does it already expose OData? Use the adapter that matches the version. This is the lowest-effort route for non-Salesforce systems.
- Can an OData layer be added cheaply? Many platforms can publish OData from a database or API gateway. A wrapper service keeps Apex out of the picture and moves the work to a service that your integration team can scale and monitor.
- Otherwise, write a custom adapter. Keep it small. Prefer pushing filtering to the external API over filtering in Apex.
Trade-offs between the choices
| Concern | OData | Cross-org | Custom |
|---|---|---|---|
| Setup effort | Low | Low | High |
| Query pushdown | Filtering, sorting, and paging by the service | Handled by the provider org's API | You implement it |
| Writes | Possible if the service supports them and the data source allows them | Possible if the provider allows them | Only the operations you code |
| Governor limit exposure | Callout limits apply | Callout limits apply | Callout limits apply, plus Apex CPU time and heap |
| Maintenance | Mostly in the external service | Minimal | Code, tests, and deployments |
Common errors and gotchas
- Choosing the wrong OData version. Validate and Sync fails or returns no tables. Compare the
DataServiceVersionorOData-Versionresponse header, or the$metadatanamespace, with the adapter type you selected. - Assuming cross-org means "same data model". The subscriber gets external objects shaped by the provider's fields. Field names carry the
__csuffix on the external object, and some types map differently. - Expecting OData features the service lacks. A service that ignores
$filterreturns everything and Salesforce filters it, or the query times out. Test queries with and without aWHEREclause. - Using a custom adapter to avoid thinking about the schema. A hand-written
sync()still has to produce stable column names and an ExternalId that uniquely identifies a row. Changing them later breaks existing external objects, relationships, and list views. - Mixing authentication with adapter capabilities. A provider that declares only
ANONYMOUSauthentication cannot be used with a named credential that requires OAuth. Match the declared authentication to the credential.
Summary of the choice
The adapter follows from the external system. A Salesforce org gets the cross-org adapter. An OData 2.0 or 4.0 service gets the matching OData adapter. Anything else gets either an OData layer placed in front of it or a custom adapter you write and maintain. The more work the external service does, the less the Salesforce side has to do and the better the performance.
Exercise
Your company stores product data in an internal inventory service. It exposes a documented REST API that returns JSON, but it has no OData support. Another team can build a small gateway service in a week. Which adapter options do you have, and which would you pick if you expect the product table to grow to millions of rows? Explain why.
Show answer
You can write a custom adapter with the Apex Connector Framework, or ask the other team to publish an OData endpoint and use the matching OData adapter. With millions of rows, pick the OData wrapper. The gateway can translate $filter, $orderby, $top, and paging into efficient queries on the real data, so the external system does the work. A custom adapter would have to implement that pushdown in Apex, and falling back to DataSource.QueryUtils.process means loading rows into Apex memory, which hits heap, CPU, and callout limits at that scale. The wrapper also leaves less Apex code to test and maintain.