Skip to content

Instantly share code, notes, and snippets.

Last active February 11, 2019 19:58
What would you like to do?
setupJson - Product2
public static String setupJson(List<String> productIds){
//get list of Apttus products and add to list of Products to return to insert/update
//this will be mapped to the Parent product later
List<String> updateIds = new List<String>();
//setup object structure dynamically with objects and relationship to master object
Map<String,String> objMap = new Map<String,String>();
String jsonSetup = REST_Utilities.jsonSetup(updateIds, objMap);
//get Product objects back to update them with a Pricebook attribute
//will be used in target org to map source org PriceBook Id to name
Map<String,Object> productFieldList = new Map<String,Object>();
productFieldList = (Map<String, Object>) JSON.deserializeUntyped(jsonSetup);
List<Pricebook2> pricebooks = new List<Pricebook2>([Select Id, Name from Pricebook2]);
Map<String,String> pMap = new Map<String,String>();
for(Pricebook2 p : pricebooks){
pMap.put(p.Id, p.Name);
String serializedProduct = JSON.serialize(productFieldList);
system.debug('json: ' + serializedProduct);
return serializedProduct;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment