You need to sign in to do that
Don't have an account?
trailhead Apex REST Callouts error: Return Value must be of type: System.HttpResponse
Hi Everyone,
Trying to complete the Rest Callouts challenge and getting this error on the last line: return strResponse;. Here is my code:
Thank you!
Trying to complete the Rest Callouts challenge and getting this error on the last line: return strResponse;. Here is my code:
public class AnimalLocator { public static HttpResponse getAnimalNameById(Integer ID){ Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+ID); request.setMethod('GET'); HttpResponse response = http.send(request); String strResponse = ''; if(response.getStatusCode()==200){ Map<String,Object> results = (Map<String,Object>) JSON.deserializeUntyped(response.getBody()); Map<String,Object> animals = (Map<String,Object>) results.get('animals'); system.debug('These are the animals:'); strResponse = string.valueOf(animals.get('name')); } return strResponse; } }
Thank you!
Your method getAnimalNameById need a return type of HttpResponse .
public static HttpResponse getAnimalNameById(Integer ID){
but you are returning string from te method.
return strResponse;
I think as per your code, you need to return String instead of HttpResponse. please use below code and let me know if it works for you.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Debasis
All Answers
Your method getAnimalNameById need a return type of HttpResponse .
public static HttpResponse getAnimalNameById(Integer ID){
but you are returning string from te method.
return strResponse;
I think as per your code, you need to return String instead of HttpResponse. please use below code and let me know if it works for you.
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Debasis