6

Can anyone suggest me how to cover the SOQL code line in test class. Due to Query failing i am not able to increase the code coverage to 75% minimum for class. Suggest me how can i achieve this . Is there any other way to increase the code coverage?

1 Answer 1

7

Mocking the external object API calls is not properly supported by SFDC yet. However, there is a pretty neat workaround by Graham Barnard. It does require some redesign of your External Object queries and it will not give you 100% test coverage (because of the isRunnningTest() statement). But it will allow you to functionally test the code that calls the external objects

http://grahambarnard.com/development/2016/02/08/mocking-external-objects/

3
  • I have tried and it is working.I wanted to make sure that ,will it be effected system if i use this approach means allows that calls the external objects functionally test the code that calls the external objects
    – user33763
    Commented Jul 13, 2016 at 8:24
  • It is passing the SOQL but the data is not coming ,when i checked the debug logs records are not showing in list for soql. Let me know if there is any idea about it.
    – user33763
    Commented Jul 13, 2016 at 10:47
  • The Mock service will not really do a request to the external object. That is impossible in test classes. You will need to add 'fake' results in your test code, e.g. like in the example: ExternalRequestModel.mockedRequests.add(mockedRequest); Commented Jul 13, 2016 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .