Introduction to Salesforce Connect for External Applications

Share this article...

Jim is the sales manager of a large real-estate giant, based in Brooklyn. The company has recently implemented Salesforce and uses data from 8 external sources to power the CRM system. The members of Jim’s team need to switch from Salesforce to the external sources and back several times a day. This involves much effort from the user and productivity is taking a big hit.

Jim and his users are not alone in facing this sort of issue; many Salesforce users have a horrid time moving between Salesforce and external applications. So, how can this problem be resolved? Salesforce Connect offers the solution, providing integration that allows users to view and manage external data from within the Salesforce application, eliminating the need to switch between systems.

In this post, we’ll learn what Salesforce Connect is and how you can set it up.

What Is Salesforce Connect?

Salesforce Connect is a powerful App Cloud integration service, which enables users of Salesforce applications to seamlessly access and handle data stored in external sources, without leaving the Salesforce native environment.

You can use Salesforce Connect to fetch data from on-premise applications, as well as cloud-based sources. You can allow all users of your Salesforce org to connect with an external data source using only one login account or create a separate login account for each user.

How Can You Link Salesforce Connect with External Applications?

You can use the following data adapters to establish a connection between an external data source and Salesforce Connect:

  1. Open Data Protocol (OData): OData is a very popular REST-based protocol, used extensively for integrating data. You can link data sources, exposed by OData 2.0 or 4.0 producers, to Salesforce Connect.
  2. Custom-developed adapters: You can also create easy-to-use adapters in Apex, which enable you to link APIs that are not in the OData format. These tailor-made adapters allow you to connect to any web API. You can also use the adapters to link to thousands of publicly available APIs.
  3. Salesforce Connector: This adapter is ideally suited if you use multiple Salesforce instances. Salesforce Connector is a very user-friendly adapter and can be used to connect external applications without any coding.

Steps to Set Up Salesforce Connect

1. Create a New External Data Source: If the external data source has more than one service, you will need to create a data source for each service. You can create a data source by completing the fields shown in the image below and clicking Save and New.

2. Create the external object and fields: Once you create the external data source, you need to click the Validate and Sync button (highlighted in the image below), to fetch the list of tables in the data source.

Then, select the tables you wish to synchronize with Salesforce and click the button Sync (highlighted below) to access the external objects just like the custom objects in your Salesforce instance.

3. Create relationships between data objects in the external source and your Salesforce instance: You can establish 3 types of relationships between the external data objects and their counterparts in your Salesforce data system: Lookup, External Lookup and Internal Lookup. The image below lists the possible parent-child data object relationships:

Once you link the data objects in the external source with those in your Salesforce instance, you are ready to access and use the external data within your native environment.

Next, we’ll review how we can develop custom adapters in Apex to access external data, using Lightning Connect.

Creating Custom Adapters for Lightning Connect

You can develop custom adapters for Lightning Connect using two widely-used abstract classes: DataSource.Provider and DataSource.DataSourceConnection.

DataSource.DataSourceConnection enables users to access and handle the data in an external source, whereas DataSource.Provider helps establish a link with the external source.

Using DataSource.Provider to set up a connection with the external data source

Before we learn how we can use DataSource.Provider, it is important to know the Provider class is prefixed by Custom- and is indicated as Lightning Connect: Custom-Adapter Connection under the field Type.

You need to write the following piece of code to create a custom adapter:

global class ProviderClass extends DataSource.Provider {
override global List getAuthenticationCapabilities() {
List capabilities = new List();
return capabilities;
override global List getCapabilities() {
List capabilities = new List();
//ROW_CREATE - Allows the users to create records
//ROW_UPATE - Allows the users to update the records
return capabilities;
override global DataSource.Connection getConnection(DataSource.ConnectionParams connectionParams) {
return new DataSourceConnectionClass();

When you create an adapter from Setup, a new Type option is displayed, which indicates your Apex Provider class, along with the standard Lightning Connect adapters provided by Salesforce.

We’ll now explore various methods used to connect with, and fetch data from, external sources.


The types of authentication supported are:

  • ANONYMOUS (no authentication)
  • BASIC (for basic authentication)

The object DataSource.AuthenticationCapability provides the enums for these authentications.


The object DataSource.Capabilities provides different enums that help execute Create, Read, Update and Delete (CRUD) operations on external objects.


This method gets called during the execution of SOQL / SOSL queries. The connection parameters will be based on the admin configurations in the External Data Source page in Setup. For more information, check out Capability Enum on the Salesforce Developers website.


DataSourceConnection abstract class contains three methods, indicated in the image below:

List<DataSource.Table> sync();
DataSource.TableResult query(DataSource.QueryContext c);
List<DataSource.TableResult> search(DataSource.SearchContext c);


This method is called when you click the Validate and Sync button on the External Data Source page in Setup. The tables and columns you define in this method will be created in your Salesforce as external tables and the table schema will be returned as a DataSource.Table object. You can create multiple external tables using a single data source. Each data table defines a set of columns using a DataSource.Columns object.

global class DataSourceConnectionClass extends DataSource.Connection {
global DataSourceConnectionClass(DataSource.ConnectionParams connectionParams) {
global DataSourceConnectionClass() {}
override global List sync() {
List tables = new List();
List columns;
columns = new List();
// Always declare these two fields.
columns.add(DataSource.Column.text('ExternalId', 255));
// These are custom fields for our external object.
// objects that are created when synced from this adapter.
columns.add(DataSource.Column.text('CustomerName', 255));
columns.add(DataSource.Column.number('LoanId', 18, 0));
tables.add(DataSource.Table.get('LoanInfo', 'Name', columns));
return tables;
view raw hosted with ❤ by GitHub

You can accommodate definitions of multiple tables using the sync method, as indicated in the image below:

tables.add(DataSource.Table.get('LoanAccountInfo', 'Name', loanAccColumns));

The LoanAccColumns accommodate the second table’s column information. When the data source is validated, you can see the two tables: LoadInfo and LoanAccountInfo. Then, you can sync these two external tables to have them and their columns created in Salesforce.


When you navigate through the data in a related list, a list view or the search bar, the system executes an SOQL query, which in turn calls this query method to fetch the data. This method returns the data in the form of a DataSource.TableResult object; however it will not handle the count, offset or limit.

override global DataSource.TableResult query(DataSource.QueryContext c) {
List<Map<String,Object>> rows = new List<Map<String,Object>>();
Map<String,Object> row = new Map<String,Object>();
row.put('CustomerName', ‘Test Customer’);
row.put('LoanId', 128364232);
row.put('ExternalId', ‘343532’);
row.put('DisplayUrl', URL.getSalesforceBaseUrl().toExternalForm() + ‘/’);
return DataSource.TableResult.get(c,rows);

Two objects can be used for setting up or reading the filters in SOQL: DataSource.Filter and DataSource.FilterType. These filters must be used with respect to the QueryContext object class.

//To find the table name
// To pull the column used in the filter condition
// to find the type of operation (EQUALS, GRETER THAN, LESS THAN or etc)
// To find the sub filters used with Not/OR/AND


The search method is executed when you run a SOSL query or use the global search in Salesforce.


Salesforce Connect is a very useful integration service that allows users in the native Salesforce environment to access and handle data from external sources in a hassle-free manner. Using the steps and the methods discussed above, you can supercharge your user’s productivity by removing the need to switch between multiple systems.


For more information check out the following resources:

Salesforce Connect: Delivering Connected Apps for Customer Success

Introducing Lightning Connect Custom Adapters

5 thoughts on “Introduction to Salesforce Connect for External Applications

  1. Is it possible to view an image from an enterprise document store (e.g. FileNet, Datastore DSX) in Salesforce?

Add Comment