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

Test class for WebService SOAP API Call


Can anyone please provide some guidance in how to go about writing test code coverage for Webservices API Calls to a 3rd party application.

Following is the code, that I am trying to get code coverage for:

 String datumapp = '{'
      + '"serial_number":"'+SerialNumber + '",'
      + '"model":"A20-R-500",'
      + '"reseller":"'+ SFDCResellerID +'",'
      + '"client":"' + SFDCClientID +'",'
      + '"package":"'+ PackageType +'",'
      + '"offsite":"'+ Offsite +'",'
      + '"data_center":"'+ DataCenter +'",'
      + '"status":"active"'
      + '}';
      Http httpProtocolInsertAppliance = new Http();       // Create HTTP request to send.
      HttpRequest requestapp = new HttpRequest(); // Set the endpoint URL.
      String endpointapp = '';
      requestapp.setHeader('Content-length', String.valueOf(datumapp.length()));

      HttpResponse responseapp = httpProtocolInsertAppliance.send(requestapp);
      System.debug(responseapp.getBody()+'APPLIANCE INSERTION CHECK 1');
      System.debug(responseapp.getHeader('Location')+'APPLIANCE INSERTION CHECK 1');
      throw new IntegrationException('Already exists');


Santhosh KumarSanthosh Kumar

It is still a bit pain to test the Call outs so users have come up with varies ways to come around the problem and still achive the test coverage. Check out these links.



Hi Pranav,


You ant test the SOAP webservice callout. Whenever code encounters the "invoke" method, it stops at that place only.


You can try to have more test coverage only by adjusting your logic.


In my case, i create separate method which only call the webservice and returns reult. That method is used by other part. In Test Method, manualy create the test data and test remaining code.

HI jitendra,

i'm posted my class and test class in this community.
I'm not getting fake response in test class. can u please tel me how to write fake response for soap webservice callouts.
Please check below link for details