You need to sign in to do that
Don't have an account?
Ab
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
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
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.