Deserialize and Assign Fields and Values to Object Sample
//create a template for each Product2 | |
Map<String,Object> prodTemplate = getListOfFields('Product2'); | |
//deserialize Product2 from JSON | |
Map<String,Product2> prodMap = (Map<String, Product2>) JSON.deserialize(prodSerialize, Map<String,Product2>.class); | |
//for each Product2 returned loop through | |
for(String p : prodMap.keySet()){ | |
//create new Product2 object | |
Product2 prodToInsert = new Product2(); | |
//initialize new Map for fields and values | |
Map<String,Object> prodValues = new Map<String,Object>(); | |
//use template for Product2 to populate for current object | |
prodValues.putAll(prodTemplate); | |
//populate Map with written values from this specific Product2 | |
prodValues = sendWrittenFields(prodMap.get(p)); | |
//from our Map, populate Product2 directly with put of field and value pair | |
for(String field : prodValues.keySet()){ | |
prodToInsert.put(field,prodValues.get(field)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment