Sub topic 6
Generating external objects with Validate and Sync
This chapter assumes you have a working external data source, as covered in the previous chapters, and basic familiarity with Setup navigation, objects, and fields. You will use Validate and Sync to turn the external system's schema into external objects.
What Validate and Sync does
An external data source only stores connection details. It does not create any objects. Validate and Sync is the action that reads the external system's schema and creates external objects from it.
The action does two things in order:
- Validate connects to the external system with the data source's settings and checks that the connection and authentication work. If this fails, no sync happens.
- Sync lists the tables the external system exposes. You pick the ones you want, and Salesforce creates an external object for each. Each external object gets custom fields that match the table's columns.
Salesforce creates external objects only for tables you select. It also creates only the fields it can map to a supported field type.
Running it
- In Setup, enter External Data Sources in Quick Find and open your data source.
- Click Validate and Sync.
- If validation succeeds, Salesforce lists the available tables. Select the ones you need.
- Click Sync.
The new external objects appear under External Objects in Setup. Their API names end in __x, and the generated custom fields end in __c.
What gets created
How the external names map to Salesforce names depends on the adapter. For an OData adapter, an entity set called Products becomes an external object, and its properties become fields.
| External schema | Salesforce result |
|---|---|
| Table or entity set | External object, API name ending in `__x` |
| Column or property | Custom field, API name ending in `__c` |
| Key column | `ExternalId` standard field |
| Row address, if available | `DisplayUrl` standard field |
| Unsupported column type | Field not created |
Two standard fields are always present. ExternalId holds the row's unique key in the external system, and DisplayUrl holds a link to the row. Chapter details on both appear in the next chapter, on the anatomy of an external object.
Running it again
Validate and Sync is repeatable. When the external schema changes, run it again to pick up the change.
- New columns are added as new fields on the existing external object.
- New tables show up in the list, so you can add them.
- Fields you edited in Salesforce, such as labels, are kept. The sync does not remove fields that disappeared from the external system, so you need to clean up those fields yourself.
Common errors
- Validation fails with an authentication error. Check the named credential and the external credential principal permissions. Make sure your user has access to the principal.
- Validation fails with a connection error. Check that the URL is correct and reachable, and that any needed remote endpoint is allowed.
- A table is missing from the list. The external system may not expose it, or the authenticated user may lack access to it in the external system.
- A column has no matching field. Its type may not be supported by the adapter.
With a custom adapter
For a custom adapter, the list of tables and columns comes from your sync() method on the DataSource.Connection class. Validate and Sync calls it, so changes to the schema you return take effect the next time you run the action.
Exercise
You added a column to a table in the external system. Does the new field appear in Salesforce automatically? What should you do, and does this copy any data?
Show answer
No. Run Validate and Sync again on the external data source. The new column is added as a field on the existing external object. It copies no rows, because only metadata is created, and data is still read live at query time.
Exercise
Validate succeeds, but a table you expected is missing from the selection list. Name two possible causes.
Show answer
The external system does not expose that table to the authenticated user, or the table's definition cannot be mapped by the adapter. Check access in the external system and the adapter's supported types.