Created
February 11, 2019 21:05
-
-
Save mpassovoy/5ce91a034bed28837a2faa525a319ee0 to your computer and use it in GitHub Desktop.
Deserialize and Assign Fields and Values to Object Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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