function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vigoroushakevigoroushake 

Custom Lightning Connect: Generating Multiple External Objects from a Single Datasource

Hi,

I currently have a custom lightning connect adapter that validates, syncs and generate an external object for a particular table in my datasource. Is it possible to have the same connector hit the same datasource and generate multiple external objects for multiple tables? I'm curious to see how this would look from coding perspective. I'm currently referencing the following:

https://developer.salesforce.com/blogs/engineering/2015/05/introducing-lightning-connect-custom-adapters.html

Thanks!
SonamSonam (Salesforce Developers) 
Yes, it is it possible to have the same connector hit the same datasource and generate multiple external objects for multiple tables.

reference:This example shows creating 2 external objects using single data source.
https://developer.salesforce.com/trailhead/lightning_connect/lightning_connect_setup
Pablo GarciaPablo Garcia
Yes. You can define n tables in the sync method of your Datasource.Connection extension class. Example:
override public List<DataSource.Table> sync() {
        List<DataSource.Table> tables = new List<DataSource.Table>();
        List<DataSource.Column> columns;
        
        columns = new List<DataSource.Column>();
        // Province object column's definition
        // Standard fields
        columns.add(DataSource.Column.url('DisplayUrl'));
        columns.add(DataSource.Column.text('ExternalId',255));
        // Custom fields
        // get(name, label, description, isSortable, isFilterable, type, length, decimalPlaces)
        columns.add(DataSource.Column.get('Name', 'Nombre', 'Name field for the table', true, true, DataSource.DataType.STRING_SHORT_TYPE, 50, 0));
        columns.add(DataSource.Column.get('Cpine', 'Código INE', 'Province code according to INE',true, true, DataSource.DataType.STRING_SHORT_TYPE, 2, 0));
        //Table creation
        DataSource.Table newTable = new DataSource.Table();
        newTable.labelSingular = 'Provincia';
        newTable.labelPlural = 'Provincias';
        newTable.name = 'Province';
        newTable.description = 'Provincias INE';
        newTable.nameColumn = 'Name';
        newTable.columns = columns;

        tables.add(newTable);

        // Municipality object column's definition
        List<DataSource.Column> muniCols = new List<DataSource.Column>();
        // Standard fields
        muniCols.add(DataSource.Column.url('DisplayUrl'));
        muniCols.add(DataSource.Column.text('ExternalId',255));
        // Custom fields
        // get(name, label, description, isSortable, isFilterable, type, length, decimalPlaces)
        muniCols.add(DataSource.Column.get('Name', 'Nombre', 'Name field for the table', true, true, DataSource.DataType.STRING_SHORT_TYPE, 100, 0));
        muniCols.add(DataSource.Column.get('Code', 'Código INE', 'Municipality code according to INE',true, true, DataSource.DataType.STRING_SHORT_TYPE, 10, 0));   
        muniCols.add(DataSource.Column.get('ProvCode', 'Código INE Provincia', 'Municipality code according to INE',true, true, DataSource.DataType.STRING_SHORT_TYPE, 2, 0));    
        // Municipality Table
        DataSource.Table muniTable = new DataSource.Table();
        muniTable.labelSingular = 'Municipio';
        muniTable.labelPlural = 'Municipios';
        muniTable.name = 'Municipality';
        muniTable.description = 'Municipios';
        muniTable.nameColumn = 'Name';
        muniTable.columns = muniCols;

        tables.add(muniTable);        

        return tables;
    }

Keep in mind that you have to know what table is accessed in the query(), search(), ... methods. You can do something like this:
if ('Province' == context.tableSelection.tableSelected) {
...
}
else {
...
}