I have below JSON, that we are getting from external system and I am trying to use json.deserializeUntype to associate it to respective maps, objects etc. And then trying to insert into respective parent and child SObjects of Salesforce. Everything goes fine until I encounter element_types list , since I am getting list of objects(List) , I am unable to cast it to map of string ,object and receive an invalid conversion at run-time list any to map string,any... My objective is also convert these list of object element_types and then receive them as key, pairs to go on further? It fails when taking object o into ele2, claiming run-time exception converting List<ANY> to MAp<String,ANY> which I understand and need a way to have convert to map? I have also tried iterating through object, but cannot get the key value pairs of object?

    global static void createElements() 
        Map<String, Object> results = new Map<String, Object>();
        Map<String, Object> elementsMap = new Map<String, Object>();

        String TemplateVerName;
        String TemplateVerUUID;
        INFF__Template_Version__c TempVerID;

            system.debug('request from form builder is  ' + results );


            system.debug('temp ver id is ' +TempVerID.Id );
            system.debug('temp  id is ' +TempVerID.INFF__Template__r.Id);

            //List<object> elements = new List<object>();
            List<object> elementsData = (List<Object>)results.get('elements');
                        List<object> elementsTypes = new List<Object>();

            system.debug('template name is ' + TemplateVerName);
            system.debug('template UUID is ' + TemplateVerUUID);
            system.debug('elements to be inserted are ' + elementsData);
            List<INFF__Standard_Element__c> stdElementToInsert = new List<INFF__Standard_Element__c>();
            List<INFF__Standard_Element__c> stdElementToUpdate = new List<INFF__Standard_Element__c>();
            List<INFF__Standard_Element_Type__c> ElementTypesToInsert = new List<INFF__Standard_Element_Type__c>();

            Map<String,Object> ele=new Map<String,Object>();

            Map<String,Object> ele1;
                        Map<String,Object> ele2;

                        Map<String,Object> elementTypeMap=new Map<String,List<Object>>();

            Map<String,String> UUIDChildParent = new Map<String,String>();
            Map<String,Id> UUIDStdElementIdMap = new  Map<String,Id>();

            for(object o : elementsData){

                ele = (Map<String,Object>)o;

                INFF__Standard_Element__c se= new INFF__Standard_Element__c(name=(String)ele.get('name'),

            system.debug('element types with ucid of respective element ' + elementTypeMap);

            for(String o : elementTypeMap.keyset()){



                RestIFF_Helper.setResponse('Elements Created ,successfully passed data into salesforce',200);

        catch(Exception e)
            //Log and handle any exceptions


  • You can try to use instanceof to determine type of the object – kurunve Dec 14 '18 at 7:30
  • @kurunve issue is not with respect to casting it to right type but "how to" get key value pair of the list object as similar to that of map – user2945545 Dec 14 '18 at 8:20
  • 1
    Can you also provide the sample JSON?? – Pranay Jaiswal Dec 14 '18 at 11:03
  • 1
    Can you update your code to actually include the line where you deserialize? – Adrian Larson Dec 14 '18 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.