Sub topic 5
Creating an external data source
An external data source is the Setup record that tells Salesforce where an outside system lives, which adapter to use to talk to it, and how to authenticate. Every external object belongs to exactly one external data source. This chapter walks through creating one, explains each setting, and covers the errors you are most likely to hit.
This chapter assumes you know the basic Salesforce data model, can navigate Setup and permission sets, and have read the earlier chapters on Salesforce Connect, adapters, and named credentials. You do not need Apex here.
What the external data source does
Salesforce Connect does not store the external rows. When a user opens an external record, or when a query runs, Salesforce makes a live callout to the external system. The external data source holds everything Salesforce needs to make that callout:
- The adapter type, such as OData 2.0, OData 4.0, cross-org, or a custom Apex adapter.
- The endpoint, either typed directly or supplied by a named credential.
- The identity type and authentication protocol.
- Options that control how requests are made and how the data is treated.
The external data source is also the object that Validate and Sync reads. It contacts the endpoint, discovers the tables, and creates external objects from them. You create the data source first, and the external objects come second.
Before you start
Gather these items before you open Setup:
- The service URL of the external system. For OData this is the root of the service, the URL that returns the service document or the
$metadatadocument when you append/$metadata. - A named credential and external credential, if the system needs authentication. Create these first, because the data source form refers to them.
- A permission set or profile that lets you manage data sources. You need the Customize Application permission.
- Confirmation that the external system accepts requests from Salesforce, including any firewall or IP allowlist rules.
Salesforce Connect also needs to be available in your org. It is an add-on license for most editions, and the External Data Sources page will not offer the adapters you expect without it.
Creating the data source in Setup
- From Setup, enter External Data Sources in Quick Find and select it.
- Click New External Data Source.
- Fill in the fields described below.
- Click Save.
Saving does not contact the external system. The connection is first tested when you run Validate and Sync, which is the next chapter.
Naming fields
| Field | Purpose | Notes |
|---|---|---|
| External Data Source | The label shown in Setup and in lists | Choose a name that tells admins which system it is. |
| Name | The API name | Letters, digits, and underscores. You cannot change it after other metadata refers to it without care. |
| Type | The adapter | Choose from the Salesforce Connect adapters. The rest of the form changes with this choice. |
The label and API name matter more than they appear to. External objects generated from this source get names such as Product__x, but the data source name appears in deployment files, in Apex that builds DataSource metadata, and in error messages. A clear name saves time later.
Connection fields
For the OData adapters, the key fields are:
- URL: the service root. If you use a named credential, the URL here is replaced by the named credential's endpoint, and you select the credential instead.
- Connection Timeout: how long Salesforce waits for the external system to respond before it gives up. The value is in seconds.
- High Data Volume: tells Salesforce the external system holds a large number of rows. This affects how some features, such as list views and lookup search, behave.
- Server Driven Pagination: lets the external system decide how many rows to return per page and supply a link to the next page.
- Custom HTTP Headers: extra headers sent with every request, for example an API version header.
- Request Compression: compresses outgoing requests when the external system supports it.
- Include in Salesforce Searches: lets global search include this source's external objects.
- Format: the wire format, JSON or Atom, for OData 2.0. OData 4.0 uses JSON.
Not every field exists for every adapter. The cross-org adapter, for example, connects to another Salesforce org and has different options. A custom adapter built with the Apex Connector Framework uses the Apex provider class you select, and shows only the fields that provider supports.
Authentication fields
Authentication has two parts: who the identity is and how the credential is sent.
Identity Type decides whose credentials Salesforce uses when it calls the external system.
| Identity type | Meaning | Typical use |
|---|---|---|
| Named Principal | One shared set of credentials for every Salesforce user | The external system does not need to know who the user is, or you apply one service account. |
| Per User | Each Salesforce user supplies their own credentials | The external system enforces its own per-user permissions. |
| Anonymous | No credentials sent | Public data only. |
Authentication Protocol decides how the credential is sent: password authentication, OAuth 2.0, or no authentication. With modern named credentials, you pick the named credential and its external credential and principal define the protocol, so you do not repeat these choices on the data source.
A frequent point of confusion: with Per User identity, each user must set up their own authentication settings before they can see any data. Users do this in their personal settings under authentication settings for external systems. An administrator can also manage the settings for users. A user who has not done this sees an authentication error instead of rows.
Choosing the options that matter
Most options have a safe default. A few deserve a deliberate decision.
Connection timeout
The timeout caps how long a single callout can take. Set it to match the external system's real response time, plus a margin. A very long timeout makes pages hang. A very short one causes intermittent failures when the external system is slow. Salesforce also enforces its own maximum callout time, so a value above that limit does not help.
Server driven pagination and High Data Volume
Without server driven pagination, Salesforce asks the external system for rows using client side paging options such as $top and $skip. Those are less efficient on large tables, and some services do not handle them consistently. If the service supports server driven paging, turning it on is usually better for large tables. Turn on High Data Volume when the table holds a large number of rows, so Salesforce adjusts features such as list view behavior to avoid expensive operations.
Writable external objects
The Writable External Objects checkbox lets users create, edit, and delete external records from Salesforce. It is off by default. Turn it on only when the external system accepts writes, the credential has write permission, and you have decided the behavior is wanted. A later chapter covers the write behavior in detail.
Search and special features
Include in Salesforce Searches makes external objects part of global search. Every search that includes the source can trigger a callout, so enable it only when users need it.
Storing the endpoint in a named credential
You can type a URL straight into the data source. Doing so ties authentication to the data source's own settings. The preferred approach is to leave the URL to the named credential:
- Create an external credential and a principal that holds the authentication details.
- Create a named credential that points to the endpoint and uses the external credential.
- In the data source, select that named credential.
- Grant users access to the external credential principal through a permission set.
This separation means you can change an endpoint or rotate a secret in one place, and sandbox-to-production moves only need a different named credential value. It also keeps secrets out of the data source record.
Verifying the data source
After saving, the detail page shows the settings and a Validate and Sync button. Click it to test the connection. If Salesforce can reach the endpoint, it lists the tables it found and lets you select them. If it cannot, it shows an error. The next chapter covers the sync step itself.
Two quick checks before you sync:
- Open the endpoint's
$metadataURL in a browser or with a command-line tool to confirm it responds and is well-formed. For example,curl -i https://example.com/odata/$metadata. - Confirm that the credential works outside Salesforce, using the same account.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Validate and Sync reports a connection or callout error | Wrong URL, endpoint down, or firewall blocking Salesforce | Test the URL, then check allowlists and certificates. |
| Authentication error for some users only | Per User identity without personal settings, or missing principal access | Have users set up authentication, or grant the permission set. |
| Certificate or SSL errors | Untrusted or expired certificate on the external system | Install a certificate signed by a trusted authority. |
| Timeout during sync | Service is slow or the metadata document is large | Raise the timeout within limits, or reduce the exposed tables. |
| No tables listed | Service document is empty or the credential cannot see the tables | Check the service and the account's permissions. |
| Adapter option missing from Type | Salesforce Connect license not enabled | Ask your Salesforce account team or admin to enable it. |
Metadata changes in the external system are not picked up automatically. If the external system adds a column, the data source does not change, and you run Validate and Sync again to refresh the external object.
Deploying data sources
An external data source is metadata (ExternalDataSource), so you can retrieve and deploy it with change sets or the metadata API. Credentials do not travel with it. After a deployment, create the matching named credential in the target org, then confirm the data source selects it. Per User settings must also be redone in the target org by each user.
Exercise
A data source works when an administrator runs Validate and Sync, but other users see an authentication error when they open an external record. The data source uses a named credential with an external credential. Name two likely causes and a fix for each.
Show answer
First, the users may lack access to the external credential principal, so grant it through a permission set. Second, if the identity type is Per User, each user has not set up their own authentication settings, so they must complete those settings in their personal settings, or an administrator must set them up for them.
Exercise
Why is it usually better to select a named credential on the data source than to type the URL and credentials directly?
Show answer
A named credential keeps the endpoint and secrets in one place, so you can change or rotate them without editing the data source, and you can use a different value in each org when moving from sandbox to production.