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
AbAb 

Test Web Service Callouts | Trigger>Asynchronous Call > Web service call out

Hello,

I have below structure of code

Triggger{
    ClassX.functionAsyn();
}

global class ClassX{
    @Future(callout=true)
    Public static void functionAsyn()
    {
      url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins='+address1+'&destinations='+address2+'&mode=driving&key=AIzaSyDCrFBIYoXyYhmEwsNcQ';
                req.setEndPoint(url); 
                resp = http.send(req);
                JSON2Apex obj = JSON2Apex.parse(resp.getBody()); 
    }
}


resp.getBody() is always nulll because  "Web Service Callouts" are not allowed,

I followed this link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

But still i am difficult to write a test class

Can anyone provide more help on this ?

thank you
 
Best Answer chosen by Ab
RaidanRaidan
Hi,

You probably want to implement the Mock class to test a callout. This is the information (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm) on how to create one.