Skip to main content

ERROR:Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String.

 

This is the code for the AnimalLocator class

 

#Apex Class

AnimalLocator:

public class AnimalLocator { public static String getAnimalNameById(Integer animalId) {         String animalName;         Http http = new Http();         HttpRequest request = new HttpRequest();         request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+animalId);         request.setMethod('GET');         HttpResponse response = http.send(request);         // If the request is successful, parse the JSON response.         if (response.getStatusCode() == 200) { Map<String, Object> r = (Map<String,object>)                 Json.deserializeUntyped(response.getBody());              Map<String,object> animal = (Map<String, object>)r.get('animal');              animalName = String.valueOf(animal.get('name'));                         }         return animalName;     } }

3 answers
  1. Jul 27, 2021, 4:11 AM

    hi, @Aditya Raj Sinha whenever we work with REST API we need to allow salesforce to hit that API, for that the endpoint URL should be added in remote site settings;

     

    go to Setup -> Remote site settings:- add a new remote site setting name it anything but URL should be https://th-apex-http-callout.herokuapp.com . then you can check the challenge

     

    Except this everything else looks good in your code so I think remote site setting is the only issue here

0/9000