1

I have implemented a custom adapter for Salesforce Connect - two Apex classes, one that implements DataSource.Provider, the other implements DataSource.Connection. I have configured an External Data Source to use the adapter, and made the external object writable.

Almost everything works - I can query the external object, my custom Tab, list views, record detail pages, related lists all work. I can even delete records. But I can't update records. I've put a "throw" into the "upsertRows" method, but it appears never to be called.

Has anyone seen this problem before? (The code is deployed using API version 42.0.)

Code has been requested:

global override List<DataSource.UpsertResult> upsertRows( DataSource.UpsertContext context )
{
    System.assert( false, JSON.serialize( context ) );

    String sObjectName = 'XXX' + context.tableSelected + '__c';
    List<sObject> records = new List<sObject>();
    for ( Map<String,Object> recordFields : context.rows )
    {
        sObject record = (sObject) Type.forName( sObjectName ).newInstance();
        for ( String fieldName : recordFields.keySet() )
        {
            if ( fieldName != 'DisplayUrl' ) record.put( fieldName == 'ExternalId' ? externalIdField : fieldName + '__c', recordFields.get( fieldName ) );
        }
        records.add( record );
    }
    List<DataSource.UpsertResult> results = new List<DataSource.UpsertResult>();
    for ( Database.UpsertResult result : Database.upsert( records ) )
    {
        results.add
        (   result.isSuccess()
        ?   DataSource.UpsertResult.success( result.getId() )
        :   DataSource.UpsertResult.failure( result.getId(), result.getErrors()[0].getMessage() )
        );
    }
    return results;
}
  • 2
    I'd recommend adding the relevant Apex from your update method - this is currently in the close queue for lacking relevant code – Brian Mansfield Mar 14 '18 at 15:36
  • I've posted the code for the upsertRows method. The assert will throw an exception if the method is called. The exception is not thrown, so I conclude that the method is not called. – Glyn Anderson Mar 14 '18 at 15:49

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.