Salesforce External Objects and ID's
Contents
[NOTE] Updated March 11, 2020. This article may have outdated content or subject matter.
What is it?
The Salesforce platform as a wide range of different relationship types available to use such as Lookup, Master Detail, Self relationships. However, the aforementioned relationship types are mainly used with internal data stored in the system. It is a different story when data is pulled and integrated with external data sources of interest. External objects support standard lookup relationships, which use the 18-character Salesforce record IDs to associate related records with each other. However, data that are stored outside your Salesforce org often doesn’t contain those record IDs.
Therefore, two special types of lookup relationships are available for external objects: external lookups and indirect lookups. To be able to use external objects, Salesforce needs a unique identification to use, however as mentioned earlier, only data originated from on the platform have the unique 18-character record id. This is where External Id’s comes into play, simply put any external id is a primary key in an external database that can be used to identify that external record that exists in Salesforce. An external ID is a custom field that has the “External ID” attribute. There are many benefits of external key including but not limited to the following:
- You can create Parent-child record relationships in a single statement in Apex 😃
- Any field marked as external id is indexed and can be used in SOQL or report filter
- It can be used to identify if record exists or not and record automatically inserted or updated using an upsert operation
- When importing custom objects, solutions, or person accounts, you can use external IDs to prevent duplicate records from being created as a result of the import operation (Note that this operation is not case-sensitive).
- Fields marked as External Ids are searchable (due to being indexed)
Connection
External objects share much of the same functionality as custom objects, except that they map to data that’s stored outside your Salesforce org. Each external object relies on an external data source definition to connect with the external system’s data. Each external object definition maps to a data table on the external system. Each of the external object’s fields maps to a table column on the external system. External objects require external data sources, this article will not focus on the connectors, but rather the concepts needed to understand the topic. For example, you can:
- Access external objects via list views, detail pages, record feeds, custom tabs, and page layouts.
- Enable create, edit, and delete operations on external objects.
- Enable Chatter feeds on external object pages for collaboration.
- Define relationships between external objects and standard or custom objects to integrate data from different data sources.
Note: If you need frequent access to large amounts of external data, ETL might still be your best option for optimal performance.
Limitations & Restrictions
Please note the following restrictions for External objects:
- Each org can have up to 100 external objects
- External objects don’t count toward the amount for custom objects
Please note the following limitations for External objects:
- Chatter feature is available, but field tracking is possible currently not available
- Reports and analytics are available but limited
- Workflows are not available yet
- Triggers are not available yet
- Formula fields are not available yet
- SOQL is available but limited
- Sharing is not available
External Object Relationships
After you’ve configured an external data source and defined external objects, you can integrate the external data into Salesforce using relationship fields or just relate existing fields. You can define three types of relationships for external objects, namely:
Lookup relationship
- Use a lookup relationship when the external data includes a column that identifies Salesforce records by their 18-character IDs, the external must contain the 18-character Salesforce record id.
- Child object be Standard, Custom or External
- Parent object can only be standard or custom
External lookup relationship
- Child object can Standard, Custom or External
- But the parent of to be External
- The values of the standard External ID field on the parent external object are matched against the values of the external lookup relationship field.
Indirect lookup relationship
- Child object must be external
- Parent object can be either standard or custom
Tips for External ID’s
A common question asked when relating two objects, one newly created and the other is existing, how can we relate the two objects without specifying an object id. To accomplish this task, 2 basic requirements must be met:
- First for the existing object you are trying to relate, ensure a custom field (number or text) is created and marked as external
- Populate the said custom field appropriately matched to the data type
Example
Assume that a field called AccountExtId (Text) was created and marked as external id, the following snippet relates a newly created Case to an existing account record where AccountExtId__c = 'first-account-created'
. Before the new Case is created the account record is added as a Sobject through the Case.Account relationship.
|
|
Author Remario Richards
Modified March 11, 2020