You need to sign in to do that
Don't have an account?
smita bhargava
TrailHead Rest Callout Challenge
I am doing the TrailHead challenge as below.
https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts
I created an aexx class with method as follows as part of the challenge.
public class AnimalLocator{
public String 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);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserialize the JSON string into collections of primitive data types.
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
// Cast the values in the 'animals' key as a list
List<Object> animals = (List<Object>) results.get('animals');
System.debug('Received the following animals:');
//for (Object animal: animals) {
// System.debug(animal);
// }
}}
In the challenge ist given like this "the method returns the value of the 'name' property (i.e., the animal name)"
so How to make the method return the animal name
Please let me know.
Thanks
Smita
https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts
I created an aexx class with method as follows as part of the challenge.
public class AnimalLocator{
public String 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);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserialize the JSON string into collections of primitive data types.
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
// Cast the values in the 'animals' key as a list
List<Object> animals = (List<Object>) results.get('animals');
System.debug('Received the following animals:');
//for (Object animal: animals) {
// System.debug(animal);
// }
}}
In the challenge ist given like this "the method returns the value of the 'name' property (i.e., the animal name)"
so How to make the method return the animal name
Please let me know.
Thanks
Smita