You need to sign in to do that
Don't have an account?
S S Malik
Non-void method might not return a value or might have statement after a return statement in callouts.
The code is as
public class testcallouts{
public static httpResponse MakeGetCallout(){
http http=new Http();
HttpRequest request=new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('GET');
httpResponse response =http.send(request);
if(response.getStatusCode() == 200) {
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<String> key = (List<String>) results.get('names');
System.debug('Received the following names:');
for(String key1:results.keySet())
{
System.debug(results.get(key1));
}}}
public static httpResponse MakePostCallout(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"sukhbir"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
system.debug('Test Start from Here');
System.debug(response.getBody());
//System.debug('The status code returned was not expected: ' +
// response.getStatusCode() + ' ' + response.getStatus());
}
else {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
//System.debug(response.getBody());
//System.debug(response.getBody());
system.debug('TEST ENDS HERE');
}
//system.debug('success Ending');
return response;
}
}
Thanks in Advance
public class testcallouts{
public static httpResponse MakeGetCallout(){
http http=new Http();
HttpRequest request=new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('GET');
httpResponse response =http.send(request);
if(response.getStatusCode() == 200) {
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<String> key = (List<String>) results.get('names');
System.debug('Received the following names:');
for(String key1:results.keySet())
{
System.debug(results.get(key1));
}}}
public static httpResponse MakePostCallout(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.itutorlms.com/test.php');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Set the body as a JSON object
request.setBody('{"name":"sukhbir"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
system.debug('Test Start from Here');
System.debug(response.getBody());
//System.debug('The status code returned was not expected: ' +
// response.getStatusCode() + ' ' + response.getStatus());
}
else {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
//System.debug(response.getBody());
//System.debug(response.getBody());
system.debug('TEST ENDS HERE');
}
//system.debug('success Ending');
return response;
}
}
Thanks in Advance
use below code,
If you dont want "return response" in this method "MakeGetCallout() " replace return response to "return null"
Hope this will help you..
mark Best ANSWER if its works for you.
Thanks
karthik
All Answers
use below code,
If you dont want "return response" in this method "MakeGetCallout() " replace return response to "return null"
Hope this will help you..
mark Best ANSWER if its works for you.
Thanks
karthik
Kartik