You need to sign in to do that
Don't have an account?
Map json data to salesforce object
Hi there,
I have integration stuff. In this i callout to external api and get data in response. This is my code.
public class covidIntegrationCallout {
public static HttpResponse makeCovidIntegrationCallout() {
Http ht = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.covid19india.org/state_district_wise.json');
request.setMethod('GET');
HttpResponse res = ht.send(request);
System.debug('========='+res);
System.debug('========='+res.getBody());
List<Covid19__c> upsertState = new List<Covid19__c>();
Map<String,Object> results = (Map<String,Object>) JSON.deserializeUntyped(res.getBody());
System.debug('----------'+results);
Map<String,Object> tempst = (Map<String,Object>)(results.get('State Unassigned'));
for(Object lst:tempst.keySet()){
system.debug('************'+lst);
}
return res;
}
}
help me to map json data to salesforce custom object Covid19__c.
any help appriciated!
Thanks in Advance
I have integration stuff. In this i callout to external api and get data in response. This is my code.
public class covidIntegrationCallout {
public static HttpResponse makeCovidIntegrationCallout() {
Http ht = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.covid19india.org/state_district_wise.json');
request.setMethod('GET');
HttpResponse res = ht.send(request);
System.debug('========='+res);
System.debug('========='+res.getBody());
List<Covid19__c> upsertState = new List<Covid19__c>();
Map<String,Object> results = (Map<String,Object>) JSON.deserializeUntyped(res.getBody());
System.debug('----------'+results);
Map<String,Object> tempst = (Map<String,Object>)(results.get('State Unassigned'));
for(Object lst:tempst.keySet()){
system.debug('************'+lst);
}
return res;
}
}
help me to map json data to salesforce custom object Covid19__c.
any help appriciated!
Thanks in Advance
>> https://salesforce.stackexchange.com/questions/158493/field-mapping-from-json-response-to-custom-object
As mentioned in the above link, you will have to write a class to deserialize the json response.
For quick reference I am adding the selected best answer in the above link below:
You might consider writing a class to deserialize into. You can add an instance method to it that does additional parsing. Then you would be able to do something like: If you get a response with many Lead records, your deserialization process would change, but the class would stay the same:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.