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
suyogya jain 6suyogya jain 6 

URGENT!!!!! Invalid conversion from runtime type List<ANY> to Map<String,ANY>

  Map<String,Object> results = (Map<String,Object>)JSON.deserializeUntyped(response.getBody());
                list<object> attchlist;
                list<ContentVersion> CV = new list<ContentVersion>();
                list<ContentDocumentLink> CDLink = new list<ContentDocumentLink>();
                Set<Id> contentDocumentIds = new Set<Id>();
                Set<FileData> fileFromSAP = new Set<FileData>();
                for(Object mapa:results.values() ){
                    Map<String,Object> tempMap = (Map<String,Object>)mapa;
                    map<string,object> attc = (Map<String,Object>)tempMap.get('Attachment');

This exception is coming while running the code...someone please help
mukesh guptamukesh gupta
Hi Suyogya,

As per in your code you are converting in MAP, this may be a issue, here you need to check in JSON
map<string,object> attc = (Map<String,Object>)tempMap.get('Attachment');

you can follow below example:-
String payload = '{"data": [{"s": "a", "i": 1}]}';
Map<String, Object> deserialized = (Map<String, Object>)JSON.deserializeUntyped(payload);
List<Map<String, Object>> data = new List<Map<String, Object>>();
for (Object instance : (List<Object>)deserialized.get('data'))
    data.add((Map<String, Object>)instance);

If this solution is usefull for you, Please mark as a Best Answer to help others.


Running into the same issue. Not sure if any one got the solution.
Invalid conversion from runtime type List<ANY> to Map<String,ANY>

Http h = new Http();
HttpResponse res = h.send(req);
 Map<String,Object> resBody = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());

List<String> fieldAPINames = new List<String>(); List<String> headerList = new List<String>();

String fieldQuery = 'SELECT ';

for(Object col : (List<Object>)resBody.get('columns')){

   Map<String, Object> colFieldMap = (Map<String, Object>)col;
   if((Boolean)colFieldMap.get('hidden') == false){
          if(fieldQuery == 'SELECT '){ 
                fieldQuery += (String)colFieldMap.get('fieldNameOrPath');
            fieldQuery += ','+(String)colFieldMap.get('fieldNameOrPath');

Any help is appreciated