You need to sign in to do that
Don't have an account?
Muskan Pradhan
System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY> error in test class
Hi,
I'm getting System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY> error in Test Class. The response body that I have created is res.setBody('[{"attributes": {"type": "Account"},"name": "test"}]');
This is the line of the main class where test class throws error.
Map<String, object> o = (Map<String, object>) JSON.deserializeUntyped(input);
Any help would be appreciated.
Thanks!!
I'm getting System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY> error in Test Class. The response body that I have created is res.setBody('[{"attributes": {"type": "Account"},"name": "test"}]');
This is the line of the main class where test class throws error.
Map<String, object> o = (Map<String, object>) JSON.deserializeUntyped(input);
Any help would be appreciated.
Thanks!!
Greetings to you!
You are getting List with JSON, so you need to parse it into List. Then you can parse it into key-value pair.
Please refer to the below links which might help you further with the above issue.
https://salesforce.stackexchange.com/questions/17549/invalid-conversion-from-runtime-type-listany-to-mapstring-any
https://salesforce.stackexchange.com/questions/234884/callout-error-invalid-conversion-from-runtime-type-listany-to-mapstring-any
I hope it helps you.
Kindly 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. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thanks for the reply!
However, I cannot make any modifications in the main class. Will have to change the test response or modify my test Class.
Thanks
Try this for setting the input:
Regards,
MKR
Is it the same row that is causing the error?
Regards,
MKR