0

I'm trying to extend the DataSource.Provider and DataSource.Connection to create a custom adapter for Lightning Connect. I'm in my developer org and have created a custom provider that shows up in the type dropdown when creating an external object data source.

I'm connecting to a web service endpoint. The connection is successful and I'm trying extend the DataSource.Connection class to sync the external data into external object.

Here is the class:

/**
    Extends the DataSource.Connection class to enable Salesforce to sync the external system’s metadata schema and to handle queries and searches of the external data. 
**/
global class DriveDataSourceConnection extends DataSource.Connection {

    private DataSource.ConnectionParams connectionInfo;

    // Constructor for DriveDataSourceConnection.
    global DriveDataSourceConnection(DataSource.ConnectionParams connectionInfo) {
        this.connectionInfo = connectionInfo;
    }

    // Called when the administrator clicks “Validate and Sync” in the user interface for the external data source.
    override global List<DataSource.Table> sync() {
        List<DataSource.Table> tables = new List<DataSource.Table>();
        List<DataSource.Column> columns;
        columns = new List<DataSource.Column>();
        columns.add(DataSource.Column.text('Name', 255));
        columns.add(DataSource.Column.text('ExternalId', 255));
        columns.add(DataSource.Column.url('DisplayUrl'));
        tables.add(DataSource.Table.get('SSO','Name',columns));
        return tables;
    }

    override global DataSource.TableResult query(DataSource.QueryContext c) {
        List<Map<String,Object>> rows = getRows();
        return DataSource.TableResult.get(c, rows);
    }

    // Helper method to get record values from the external system for the Sample table.
    private List<Map<String, Object>> getRows () {
        List<Map<String,Object>> rows = new List<Map<String,Object>>();
        MyService cs = new MyService();
        MyService.UserObject obj = null;
        obj = cs.getUser();
        rows.add(foundRow(obj));
        return rows;

    }

     // Populate a row based on values from the external system.
     private Map<String,Object> foundRow(MyService.UserObject obj) {
        Map<String,Object> row = new Map<String,Object>();
        row.put('ExternalId', string.valueOf(obj.guid));
        row.put('DisplayUrl', string.valueOf(obj.token));
        row.put('Name', string.valueOf(obj.name));        
        return row;
    }   

     override global List<DataSource.TableResult> search(DataSource.SearchContext c) {        
         return DataSource.SearchUtils.searchByName(c, this);
     }

}

When I click "Validate and Sync" it creates the external object in Salesforce with the required two standard fields and currently the one custom field I have specified. When I click to "sync" the data, I can open developer console and I can see the data coming back from the web service call in the getRows() and foundRow() methods. However, if I try and execute a simple soql query in developer console, it will show that a record was returned, but no data is displaying in the query window in the console, even though it shows 1 record returned from the web service. I'm only testing with 1 record for now. I thought it might be a permission issue and I checked the system administrator profile and the field level security was visible from the fields on the external object.

Any idea why I'm not showing data in my soql query on the external data?

  • Does your query have anything in specific which is not supported by External Object as specified here -- help.salesforce.com/… – Jayant Das Apr 5 '18 at 20:26
  • No, it is just a simple query select name__c from MyTable__x – Dman100 Apr 5 '18 at 20:28
  • Do you see the objects synced in the external data source section? I would assume so, but cross checking. – Jayant Das Apr 5 '18 at 20:41
  • Under the external data source, it shows the external object and I can drill into the external object metadata and it shows the object, fields, page layout, etc. But, just no data is showing when I query. I will get a result of 1 record returned in the developer console when I run the query, but I don't see the data. In the debug, I do see the data is getting returned though. – Dman100 Apr 5 '18 at 21:07
  • Clueless. You may like to try dev console in a different browser or restart your browser and try. I saw couple of other posts but just opposite scenario. At least you are fine from the data perspective as you can see those in the logs. – Jayant Das Apr 5 '18 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.