0

It seems that Salesforce does not provide adequate tools to get a Testcoverage for external Objects.

There are some Workarounds:

  1. Unit Testing External Object with Mocked Data
  2. Apex Test coverage on External Objects

I followed this example, but my code still fails with:

System.UnexpectedException: common.exception.SfdcSqlException: We encountered an unexpected error. Contact Salesforce Customer Support. Error ID: 106104562-756784 (796685131)
c:/Users/XXXXX/Documents/GIT/xxx/force-app/main/default/classes/IntrexxSyncMonitor.cls:23:1

Thats the code:

@IsTest(SeeAllData=true)
class IntrexxSyncMonitorTest {

class Mock extends IntrexxQuery
{
    final List<SomeObject__x> externalRecords;
    Mock(List<SomeObject__x> externalRecords)
    {
        this.externalRecords = externalRecords;
    }

    protected override List<SObject> passThrough(List<SObject> records)
    {
        return externalRecords;
    }
}
  static testmethod void TestIntrexxSyncMonitor() {

    List<SomeObject__x> mockRecords = new List<SomeObject__x>();
    SomeObject__x record = new SomeObject__x(ExternalId = '00T3F00000HudxFUAR', STR_ABTEILUNGPRODUKTBEREICH__c = 'Abteilung',STR_EMAIL__c = 'xxx',STR_FAXNUMMER__c = '07721 FAXNUMMER',STR_KOSTENSTELLE__c = 'KOSTENSTELLE 001',STR_MITARBEITERID__c = 'ABCDEF',STR_MOBILNR__c ='0151 123 456 78',STR_ONEHRID__c = 'a021X000002HHN5QAO',STR_TELEFONNUMMERDIEUEBERNOMME__c = '0152 987 654 32');
    mockRecords.add(record);

    IntrexxQuery.setMock(new Mock(mockRecords));

  Test.startTest();
  IntrexxSyncMonitor.syncIntrexxObjects();
  Test.stopTest();
  [...ASSERTIONS...]
   }
}

IntrexxQuery.cls

public virtual inherited sharing class IntrexxQuery
{
  public static List<SObject> records(List<SObject> records)
  {
    System.debug('GOT HERE 2;');
    return instance.passThrough(records);
  }

  static IntrexxQuery instance = new IntrexxQuery();
  @TestVisible static void setMock(IntrexxQuery mock) { instance = mock; }

  protected virtual List<SObject> passThrough(List<SObject> records)
  {
      return records;
  }
}

and thats the line which causes the exception:

List<SomeObject__x> rows = IntrexxQuery.records([SELECT STR_ABTEILUNGPRODUKTBEREICH__c,STR_EMAIL__c,STR_FAXNUMMER__c,STR_KOSTENSTELLE__c,STR_MITARBEITERID__c,STR_MOBILNR__c,STR_ONEHRID__c,STR_TELEFONNUMMERDIEUEBERNOMME__c FROM SomeObject__x]);

Any idea why known "worarounds" to mockup external objects does not work in my case?

  • 1
    I think I would pass in a query string to records(...) and then evaluate it in the IntrexxQuery method. This will allow your injected mockquery object to return sobjects while the real code executes the SOQL from the string – cropredy Feb 5 at 2:02

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.