Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Introduction to Salesforce Connect for External Applications
Introduction to Salesforce Connect for External Applications
global class ProviderClass extends DataSource.Provider {
override global List getAuthenticationCapabilities() {
List capabilities = new List();
capabilities.add(DataSource.AuthenticationCapability.ANONYMOUS);
return capabilities;
}
override global List getCapabilities() {
List capabilities = new List();
capabilities.add(DataSource.Capability.ROW_QUERY);
capabilities.add(DataSource.Capability.SEARCH);
//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();
}
}
List<DataSource.Table> sync();
DataSource.TableResult query(DataSource.QueryContext c);
List<DataSource.TableResult> search(DataSource.SearchContext c);
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));
columns.add(DataSource.Column.url('DisplayUrl'));
// 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;
}
tables.add(DataSource.Table.get('LoanAccountInfo', 'Name', loanAccColumns));
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() + ‘/’);
rows.add(row);
return DataSource.TableResult.get(c,rows);
}
//To find the table name
queryContext.tableSelection.tableselected
// To pull the column used in the filter condition
queryContext.tableSelection.filter.columnName
// to find the type of operation (EQUALS, GRETER THAN, LESS THAN or etc)
queryContext.tableSelection.filter.type
// To find the sub filters used with Not/OR/AND
queryContext.tableSelection.filter.subfilter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment