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?
{
@HttpPost
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;
try
{
results=RestIFF_Helper.getRequestBody();
TemplateVerName=(String)results.get('name');
TemplateVerUUID=(String)results.get('uuid');
system.debug('request from form builder is ' + results );
TempVerID=BaseIFF_TempVersion.getTempVer(TemplateVerUUID);
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;
elementTypeMap.put((String)ele.get('uuid'),ele.get('element_types'));
UUIDChildParent.put((String)ele.get('uuid'),(String)ele.get('parent_uuid'));
INFF__Standard_Element__c se= new INFF__Standard_Element__c(name=(String)ele.get('name'),
UUID__c=(String)ele.get('uuid'),Template_Version__c=TempVerID.Id,
Order__c=(Decimal)ele.get('order')
);
stdElementToInsert.add(se);
}
system.debug('element types with ucid of respective element ' + elementTypeMap);
for(String o : elementTypeMap.keyset()){
ele2=(Map<STring,object>)elementTypeMap.get(o);
}
if(!results.isEmpty())
RestIFF_Helper.setResponse('Elements Created ,successfully passed data into salesforce',200);
}
catch(Exception e)
{
//Log and handle any exceptions
}
}
}
instanceof
to determine type of the object – kurunve Dec 14 '18 at 7:30