0

I Have the class AnimalLocator and a method getAnimalNameById

  HttpResponse response = http.send(request);

    if(response.getStatusCode() == 200){

        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
        animal = (Map<String, Object>) results.get('animal');

    }

    return (String)animal.get('name');

when return the name of animal map I get the error "Illegal conversion from String to System.HttpResponse" this problem it is return line

return (String)animal.get('name');
2

It appears that your method is typed as

HttpResponse getAnimalNameById()

This indicates to Apex that your method returns an HttpResponse, but the value you're actually returning is a String. The error results because the String value cannot be converted to the expected return type for this function.

I believe this is a Trailhead module; if so, please make sure that you are returning the data type that is expected by Trailhead for and that your method is declared with the same return type.

  • Yes thank you. When i created the method I put HttpResponse instead of a String – Barbilque Jul 24 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.