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
Ram Shiva KumarRam Shiva Kumar 

Test Class for External object Data

Hi,
This is regarding the code coverage for the class in which we have used the external object. in our  class we are fetching the data from the External object.We have written a test class  in such away that, we skipped (using  Test.isRunningtest() ) the  query  which is fetching the data from the external object. But unfortunately we are getting code coverage only 50%. at least we should  improve the code coverge to 80%  for that class.
So please  suggest us how to proceed further.


Kind Regards,
Siva.
SonamSonam (Salesforce Developers) 
Reading your setup implementation I would recommend you using the "HTTPCalloutMock" interface for testing the calls you have made to the external DB in your code . As the Soql query calls are HTTP calls made to external data service; making use of "HttpCalloutMock" interface is what will help you testing these calls. 

You might already have the following information but these below links give some information about testing external callouts by mocking responses. 

https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html 
http://grahambarnard.com/development/2016/02/08/mocking-external-objects/
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm 
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing.htm 
 
Marcio_FritschMarcio_Fritsch
Hi Ram,
I would suggest you to implement a kind of bypass for the external object, once you can pass
throught the test class the data such:

List<externalobject__x>partsList =     new List<externalobject__x>();            
partsList     = (!mockData.isEmpty()) ? mockData : [select id, value__c from externalobject__x limit 10 ];
Ashwani Kumar 163Ashwani Kumar 163
Does any one have the solution for this? Test class on external object data ?
Marcio_FritschMarcio_Fritsch
@ashwani Kumar, I think what I proposed above is some solution.