Skip to content

Instantly share code, notes, and snippets.

Embed
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>();
updateIds.addAll(productIds);
//setup object structure dynamically with objects and relationship to master object
Map<String,String> objMap = new Map<String,String>();
objMap.put('Product2','Id');
objMap.put('PriceBookEntry','Product2Id');
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);
}
productFieldList.put('Pricebook2',pMap);
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
You can’t perform that action at this time.