Sub topic 7
Anatomy of an external object
This chapter assumes you know the Salesforce data model, basic SOQL, and how Validate and Sync creates external objects from an external data source. Here you will learn what an external object contains once it exists.
What an external object is
An external object is a Salesforce object definition that points at a table in another system. The definition lives in your org's metadata. The rows do not. Each time a user opens a list view or runs a query, Salesforce Connect fetches the rows from the external system.
The API name of an external object ends in __x, where a custom object would end in __c. A Product__x object might map to a Products table in an ERP system.
The standard fields
Every external object has two standard fields that matter most.
| Field | Purpose |
|---|---|
| `ExternalId` | Holds the unique key of the row in the external system. Salesforce uses it to identify the row. |
| `DisplayUrl` | Holds a URL that shows the record in the external system. Salesforce uses it for links. |
The object also has an Id field. Salesforce assigns this ID to a row when it retrieves the row. Do not treat it as a permanent key. Use ExternalId when you need to refer to the same external row again.
Each external object also has a name field. You choose which external column acts as the name when you run Validate and Sync. The name field is what appears in record headers and lookup results.
Custom fields and column mapping
Every other column becomes a custom field ending in __c. Each field remembers the external column it came from. This setting is called the External Column Name.
Salesforce maps the external data type to a Salesforce field type. A text column becomes a Text field. A numeric column becomes a Number field. A date column becomes a Date field. You can change a field's label, and you can change the field's API name only if you keep the external column mapping intact.
Querying the fields
You query an external object with SOQL in the same way as any other object. The query below uses both standard fields and two custom fields.
SELECT ExternalId, DisplayUrl, Name__c, Price__c
FROM Product__x
WHERE Price__c > 100
ORDER BY Name__c
LIMIT 20Salesforce Connect turns this query into a live request. The adapter sends the filter, sort, and limit to the external system where it can. The external system returns only the matching rows.
How external objects differ from custom objects
An external object looks like a custom object in Setup, but it behaves differently in several ways.
- Salesforce does not store the data, so storage limits for records do not apply to it.
- Some features that depend on stored data are limited or unavailable. Examples are reports with certain joins, and some automation.
- Writes work only if the data source allows writes and the external system supports them.
- Each read depends on the external system. If that system is slow or offline, the object is slow or unavailable.
Putting it together
When you read an external object, three things happen. Salesforce looks up the object definition in metadata. The adapter translates the query and calls the external system. The results come back as rows with ExternalId, DisplayUrl, and your mapped fields. Because of this, a well-chosen ExternalId and name field make the object easy to use and reliable to relate to other records.
Exercise
A teammate wants to store the Salesforce Id of an external row in another system so they can find the row later. What should they store instead, and why?
Show answer
They should store the ExternalId. Salesforce assigns the Id when it retrieves a row and you should not rely on it staying the same. ExternalId is the key from the external system, so it identifies the same row every time.