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):
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_examples.htm?search_text=github
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:
columnsSelected
- List of columns to query. Corresponds to the SELECT clause in a SOQL or SOSL query.
filter
- 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.
order
- Identifies the order for sorting the query results. Corresponds to the ORDER BY clause in a SOQL or SOSL query.
tableSelected
- 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'
Then:
- 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.