5

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?

6

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/

  • 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 Jul 13 '16 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 Jul 13 '16 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); – Guy Clairbois Jul 13 '16 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.