Salesforce

Salesforce Integration with External Objects

If you want to inject the external data sources like GraphQL, URL, Amazon DynamoDB, etc. into Salesforce, it stores them in the form of objects known as external objects. Let’s consider a scenario. An agent is working on MySQL that includes three tables in one database named “Product”. He wants to store this in the Salesforce Cloud. Now, he contacted the Salesforce administrator to load all the tables into Salesforce. Let’s see how to integrate the external sources into Salesforce with examples.

External Data Source

External Data Sources comes under Salesforce integration which is used to connect to another Salesforce Org or a third-party database or content system. In our scenario, it is like a database that contains multiple tables. In Salesforce Org, we can find it under “Quick Find”.

  1. External Data Source: We need to provide the data source name that is a friendly label to display in the Salesforce UI.
  2. Name: It is the Unique Identifier that refers to the external data source API.
  3. Type: It refers to the data source type. Currently, Salesforce supports the following types:

External Object

It is available under Integrations (under “Quick Find”).The external object in Salesforce is similar to the existing Salesforce (Standard/Custom) object which stores the information. It depends upon the external data source. In our scenario, it stores 25 tables. We need to provide the external object information that includes the label and plural label.

Next, we need to specify the external connection detail that takes the external data source (LookUp) and table name.

Example 1: Type as OData 2.0

In this scenario, we load the following database available in the “services.odata.org” website:

https://services.odata.org/V2/(S(pz0owyn25w1tl3soeq4og3oq))/OData/OData.svc/

This is the public website that is used for the demo. This database includes the “Products”, “Categories”, and “Suppliers” tables. These can be loaded as the external objects.

Let’s load the suppliers and products data.

After navigating to external data sources, create the data source from the previous website by clicking the “New External Data Source” button.

Here, the external data source API name is the “Product_details”, the type is “Salesforce Connect: OData 2.0” and the URL is mentioned previously.

Click on “Save”.

Now, we need to create the external objects from this external data source. To do this, click on “Validate and Sync”.

We can see that the data source is successfully synced. Now, select the “Product and Supplier” by specifying the name field as the name for both objects. Then, click on “Sync now”.

Navigate to “External Objects” and check whether these two objects are created or not.

Product Object Details:

Supplier Object Details:

Example 2: Type as OData 4.0

In this scenario, we load the following database that is available in the “services.odata.org” website:

https://services.odata.org/TripPinRESTierService/(S(5rcm2szylojhnp5bnbbdjhhf))/

This is the public website that is used for the demo. This database includes the “Airlines”, “Airports”, and “Person” tables. These can be loaded as the external objects.

Let’s load all three tables.

Here, the Airport_details is the data source name and type is “Salesforce Connect: OData 4.0”. Click on “Validate and Sync”.

Update the name fields in all three tables. Now, select all the tables and click on “Sync”.

For Airline – The name is the AirlineCode.
For Airport – The name is the Name.
For Person – The name is the UserName.

We can see that the external objects were created.

SOQL Queries on External Objects

Let’s see how to query on external objects using SOQL. The external objects are suffixed with “__x”. The original fields are suffixed with “__c”.

Example 1:

Let’s write an SOQL query on the “Person” external object. Select the ID and Username.

SELECT id ,UserName__c from Person__x

Output:

Example 2:
Let’s write an SOQL query on the “Airline” external object that selects the airline name as “Shanghai Airline”.

SELECT id ,AirlineCode__c, Name__c from Airline__x  where Name__c = 'Shanghai Airline'

Output:
There is only one record with the “Shanghai Airline” name.

Creating Tabs for External Objects

If you want to see the records that exist in the external object, you need to create a tab. Then, we can see the records on the UI.

In “Quick Find”, search for “Tabs” and click on “New”.

Select the object as “Airport” and the tab style as “Airplane”. Then, click on “Next”.

Add this tab to all profiles and go to “Next”.

Add this tab to the custom apps and save it.

Now, go to the App Launcher and search for airports. You will see all records related to airport.

Conclusion

We learned how to integrate the external objects with Salesforce with the external data sources. As part of this guide, we collected the data from the “services.odata.org” website with the OData 2.0 and OData 4.0 types. Then, we learned how to query on these external objects with two different examples. The records that are present in the external objects can be seen from the Salesforce UI (search from the App Launcher) by creating tabs for each external object individually.

About the author

Gottumukkala Sravan Kumar

B tech-hon's in Information Technology; Known programming languages - Python, R , PHP MySQL; Published 500+ articles on computer science domain