function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raksha NarayanRaksha Narayan 

deserialize map<string,list<sobject>> in apex

I have a map, map<string,list<sobject>> mapdata= new map<string,list<sobject>>(); storing the data. the list<sobject> is returning values in JSON format. How to deserialize it?
 
VinayVinay (Salesforce Developers) 
Hi Raksha,

Try below snippet.

String s = res.getBody();
List<Account> accounts = (List<Account>) JSON.deserialize(s, List<Account>.class);

Review below sample references for more information.

https://developer.salesforce.com/forums/?id=906F00000008r36IAA

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_json.htm

Copy and paste your JSON into http://json2apex.herokuapp.com/ and try the generated code.

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
Raksha NarayanRaksha Narayan
Hi Vinay,
what is res in this line of code String s = res.getBody(); ?
 
VinayVinay (Salesforce Developers) 
Hi Raksha,

I was refering to response.

String s = res.getBody(); //res is the response.

Please mark as Best Answer if above information was helpful so that it can help others in the future.

Thanks,
Vinay Kumar