Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jsonSetup-Generic
public static String jsonSetup(List<String> objectIds, Map<String,String> queryHelper){
Map<String,Object> masterMap = new Map<String,Object>();
List<String> objIds = objectIds;
for(String s : queryHelper.keySet()){
List<String> fieldList = new List<String>();
fieldList.addAll(getListOfFields(s).keySet());
String query = ' SELECT ' + String.join( fieldList, ',' ) +' FROM ' + s + ' WHERE ' + queryHelper.get(s) + ' in :objIds ';
List<SObject> records = Database.query(query);
Map<String,Object> relatedRecords = new Map<String,Object>();
for(sObject r : records){
relatedRecords.put(r.Id,sendWrittenFields(r));
}
masterMap.put(s,relatedRecords);
}
String serializedJSON = JSON.serialize(masterMap);
system.debug('REST_Utilities.jsonSetup: ' + serializedJSON);
return serializedJSON;
}
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.