Skip to content

Instantly share code, notes, and snippets.

@mpassovoy
Last active February 11, 2019 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpassovoy/bb2638a092ae160f3120d7c66b8ff3a8 to your computer and use it in GitHub Desktop.
Save mpassovoy/bb2638a092ae160f3120d7c66b8ff3a8 to your computer and use it in GitHub Desktop.
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