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
ArunaAruna 

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

nvalid 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){
          headerList.add((String)colFieldMap.get('label'));
          fieldAPINames.add((String)colFieldMap.get('fieldNameOrPath'));
          if(fieldQuery == 'SELECT '){ 
                fieldQuery += (String)colFieldMap.get('fieldNameOrPath');
           }
          else
        {
            fieldQuery += ','+(String)colFieldMap.get('fieldNameOrPath');
         }
    }
}

Any help is appreciated 
Jaya Karthik  karnatiJaya Karthik karnati
Hi Aruna ,

at which line were you getting this error.

Thanks,
karthik
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Aruna,

Can you try something like below to parse the response,
 
Map<String, Object> tmpResult = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());

List<Object> resultList = (List<Object>)(tmpResult.get('columns'));

Now iterate over the resultlist in for loop.

If this solution helps, Please mark it as best answer.

Thanks,