Skip To Content
Back to Blog

How to use Salesforce Lightning Connect to show a related list of external data

By 12.14.15
Reading time: 4 minutes

Here is a hands-on guide to using Salesforce Lightning Connect to show a related list of external data for a given account. Let us first configure the External Data Source.

First, go to Setup -> Manage External Data Sources -> Click New External Data Source.

Here let’s choose the name and type of our data source. I will create an external data source called Third Party System of type Lightning Connect: OData 2.0. For Parameters, I will enter the OData service URL http://orderdb.herokuapp.com/orders.svc/ I will leave the rest of the fields with their default values. Click Save.

The page refreshes and shows you the detail view of your newly created data source. Notice the related list called External Objects. It should be empty. We are now ready to add our external objects that are provided by the newly added data source. Click Validate and Sync.

The validate status should be “Success” and on the related list for external objects you will see all the available resources surfaced as available objects. You can now choose which resources/tables you want to sync. Consider each Custom External Object to be a Table. Let’s select Payments. Click Sync.

You should be taken back to the External Data Source detail page where you will now see the previously selected table Payments as an external object in the related list.

Now that we have setup this object, we need to surface it somehow. I will surface this object’s data using two methods. The first method will be creating a Custom Tab where end users can create various views, and browse the data in a read-only fashion. The second method will be showing this data contextually in the Account Page layout. The data shown will only be related to the account being viewed. This will be done by adding a lookup on the External Object to the Account object based on a custom external and required field.

Method #1 – Custom Tab, All Records

Go to Setup -> Create -> Tabs

On the Custom Object Tabs section, click on New, choose Payments as the object and choose a style. Click Next. In the Add to Profiles page, I left the defaults and clicked Next. In the Add To Custom Apps page, choose the App that you want this tab to be available for.

Once you have completed creating a Custom Tab. We now need to modify our target App to have this custom Tab appear After the Home tab or in any order that you prefer. Click Setup -> Create -> Apps. Since I am in the Sales App, I will click on Edit for Sales App. In the list of Selected Tabs, I will move the Payments item up to be right after Home. Click Save.

Awesome! Now you will find the Payments tab after the Home Tab and if you click it, you will be taken to a standard Salesforce views page. I recommend you edit the All view and add relevant columns.

You can click on any Payment record and drill into a standard page layout. Notice that there is no delete or edit buttons as this data is read-only. This data is surfaced by Salesforce as if it were Salesforce data but the actual data remains at its source. That is the power Salesforce Lightning Connect!

TIP: Don’t forget to edit the Search Layout on the Payment Object for the Payments Tab layout to modify the Recently Viewed columns.

Method #2: Related List on Account Page Layout 

At times you may only want to show external data as it relates to a record you are already reviewing. For example, you may have an account that you are viewing in Salesforce and you want to see a related list of only Payments associated to the current account. This can be done.

To do this, we will have to create a Indirect Lookup Relationship on the External Object pointing to an unique and external ID  field on the Account Object. Let’s first create this field on the Account Object.

Go to Setup -> Customize -> Accounts -> Fields. On the Account Custom Fields & Relationships section, click New. Choose Text field and name it User_ID. This is meant to match the UserID column in the Payments object. You must make check External ID as well as Unique. I left the visibility to the defaults and ensured this field gets added to all the Account Page Layouts.

Go back to the setup of the External Object Payments. On the Custom Fields & Relationships section, click New. Choose Indirect Relationship, click Next. The next screen will have a drop down of all available objects that have a Unique External ID field. Since we added this to the Account object in an earlier step, we should see Account as an option in the dropdown. Click Next, and you’ll then see a drop down with all the available unique external ID fields that are on the object. Choose User_Id__c, click Next. Leave the default field label as Account, field name should be Account, and External Column Name should be userID. (The External Column Name is case sensitive and must match the actual external object fieldname, not the label)

Click Next, Setup FLS, I left it with the default options, click Next. Add the lookup field to the Payments Page Layout by clicking Next. Finally, add a related list to the various Account Page Layouts by clicking Next. Click Save. The end result should be a new custom indirect lookup field.

Now, go the an Account, you will find the Payments related list at the bottom. Where this shows up can be changed by changing the page layout. Notice how the related list is empty. It is empty because we have not populated our Account User ID column. Let’s do that.

Edit the Account and set the User ID to the value of “1”. Save the record. The page will refresh and if you now go to the Related List, you’ll find all the records from the External Data Source that have a “1” in the userID column. Similar to method #1, you can now view more details by clicking into one of the records.

TIP: When you added the External Object, you can change the label for the columns to make things more appealing. You can also change precision on Decimal fields.

There you have it. Salesforce Lightning Connect in all its glory. If anyone asks you, “How fast is it?” Gladly respond, “Lightning Fast.”

Interested in learning more? Click here to get in touch so we can learn more about what your custom Lightning needs!

This blog originally appeared on SF for You, a blog by Silverline Technical Architect Gean Martinez. 

We don't support Internet Explorer

Please use Chrome, Safari, Firefox, or Edge to view this site.