I want to connect the external database from salesforce. I have developed the custom adapter (DataSource.Connection class and DataSource.Provider class).

In connection class, Sync method is working and I have created 4 external object using Sync method. But I am facing issue in structuring the query, search etc others methods and how to make callouts?

I have already referred this link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_start.htm but didnt get proper solution.

Can anyone share the sample code to make callouts? Thanks in advance.

Regards, Amit

1 Answer 1


These examples were the most helpful for me (examples of SF Connect custom adapters for various web services including GitHub, Google Drive, and so on):


When the platform calls the DataSource.Connection class's query method, the parameter passed in is the class DataSource.QueryContext. This gives you all of the information of the query context in which you are trying to load external object records (documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_queryMoreToken).

Specifically, the DataSource.QueryContext attribute tableSelection, of type DataSource.TableSelection, contains all of the information you need to structure your callouts (documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_DataSource_TableSelection.htm#apex_class_DataSource_TableSelection).

The DataSource.TableSelection class has the properties:


  • List of columns to query. Corresponds to the SELECT clause in a SOQL or SOSL query.


  • Identifies the query filter, which can be a compound filter that has a list of subfilters. The filter corresponds to the WHERE clause in a SOQL or SOSL query.


  • Identifies the order for sorting the query results. Corresponds to the ORDER BY clause in a SOQL or SOSL query.


  • Name of the table to query. Corresponds to the FROM clause in a SOQL or SOSL query.

If we take a simple example, where we have some external object Sample__x that we're trying to load, given its indirect lookup to an Account in the external system:

SELECT ExternalId, Account__c, Some_Property__c FROM Sample__x WHERE Account__c = '1234'


  • columnsSelected: [{columnName=ExternalId, ...}, {columnName=Account__c, ...}, {columnName=Some_Property__c, ...}]
  • filter: {columnName=Account, columnValue='1234', ...}
  • tableSelected: 'Sample__x'

I suggest looking through the documentation in the DataSource namespace, there is quite a good deal of other possibilities and useful classes beyond what the simple example above gives you, including search and query pagination.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .