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
S S MalikS 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
Best Answer chosen by S S Malik
karthikeyan perumalkarthikeyan perumal
Hello, 

use below code, 
 
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));
        }
        }
        return response; 
        }
    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;
}   
}

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

karthikeyan perumalkarthikeyan perumal
Hello, 

use below code, 
 
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));
        }
        }
        return response; 
        }
    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;
}   
}

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
 
This was selected as the best answer
S S MalikS S Malik
Thanks
Kartik