You need to sign in to do that
Don't have an account?
Jerry Clifft
How do I take this HTTPResponse data and write to a Salesforce Object?
I am new to API Integration and I have a question. I did the trailhead for API Integration, but I did not learn the final part of what I needed.
The following code works just fine the developer console.
But what I really want to do is write (Create records, one per debug line) of this data to a new Salesforce Object call Animals in a field name TypeOfAnimal. Can someone please provide an example of how to do this please.
Thanks
Jerry
The following code works just fine the developer console.
Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals'); 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); } }I can use the debug screen to see all the "animals" that returned.
But what I really want to do is write (Create records, one per debug line) of this data to a new Salesforce Object call Animals in a field name TypeOfAnimal. Can someone please provide an example of how to do this please.
Thanks
Jerry
Please modify your code as below.
Hope this helps you!
If this helps you, please mark it as solved.
Thanks and Regards
Sandhya
All Answers
Please modify your code as below.
Hope this helps you!
If this helps you, please mark it as solved.
Thanks and Regards
Sandhya