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
Edwin KEdwin K 

Test method for apex batch calling external web service

Hi.

 

I want to ask how to create a test method for apex batch where there is method calling external web service? the external web service is created from generate apex from wsdl.. Any suggestions would be great..

Thanks..

shra1_devshra1_dev

Test methods do not allow callouts.

 

So dont handle the response where you are making a callout. do callout in one method and handle response in other method.

 

i hope you understand else post your code.

 

 

Regards,

Shravan

Devendra NataniDevendra Natani

Hi,

 

Webservice callouts are not allowed using test methods. Instead of sending the webservice request, you can prepare the sample reponse data of webservice and use that in testmethods.

 

Please let me know if there is any issue.

 

Thanks,

Devendra Natani

Blog

Edwin KEdwin K

Hi, I still don't understand how to do it..

 

Here is my code snippet :

 

Global class UpdateInboxBatch implements Database.Batchable<sObject>,Database.AllowsCallouts
{

...

global void execute (Database.BatchableContext BC, List<Response__c> ListResponse)
    {

        simple code ...

        Star_Service.ArrayOfMobileData arrPhone = new Star_Service.ArrayOfMobileData();
        arrPhone.MobileData = arrDataMobile;
        service.updateInbox(arrPhone);

}

...

}

 

"Star_Service" is my external web service generated from wsdl.. How ot test that method? Any suggestions?

Thanks...

 

 

Edwin