+ Start a Discussion
Vishal Negandhi 16Vishal Negandhi 16 

External Objects - Test Classes

Hello Experts,

We are using external objects in our salesforce instance and it works fine. However, we use a VF page to display the data in these objects for grouping. Now, we do not use any custom connector so every time we run a SOQL on the external object, there's a callout made to the system and data fetched. 

How do we capture this in test classes?
We tried a few approaches like
     - mock callouts but it doesn't work for this case.  
     - entering dummy data in the external object but that's not possible. 

Code snippet below:
externalSalesHistoryList = [select ExternalId, some_other_fields from CUSTOMER_SALES_HISTORY__x where SAP_CUSTOMER_NUMBER__c =:currentAccountRecord.SAP_CUSTOMER_NUMBER__c order by PRODUCT_TYPE__c, PRODUCT_LINE__c LIMIT : Limits.getLimitQueryRows()- Limits.getQueryRows()];

This is the query and this is when the salesforce sends out a callout. Now, everytime this code runs from a test class - it returns no data. 

We have some how managed to get a good coverage using Test.isRunningTest() method, but would like to understand if there's a better way of handling this. 
Vishal Negandhi 16Vishal Negandhi 16
So adding to this, we also tried using SeeAllData = true but since this data isn't stored in Salesforce but coming from an external source nothing gets covered. 
In fact, this SOQL itself throws an exception : common.exception.SfdcSqlException. 
I believe this is because this SOQL within itself has a callout to be made.