Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. //Class to generate a JSON body
  2. public class generateBodyClass {
  3.  
  4. public String getRequestBody(List<Element__c> elementRecords) {
  5. List<JSONRecordInterface> jsonRecords = new List<JSONRecordInterface>();
  6. for ( Element__c rec : elementRecords) {
  7. String action = rec.Action__c;
  8. String entity = rec.Object_Name__c;
  9. String recordId = rec.Record_Id__c;
  10.  
  11. List<EntityVersions__mdt> mappings = [SELECT DeveloperName, version__c FROM EntityVersions__mdt];
  12. Map<String, String> entityVersions = new Map<String, String>();
  13. for(EntityVersions__mdt mdt : mappings) {
  14. entityVersions.put(mdt.DeveloperName, mdt.version__c);
  15. }
  16. JSONRecordInterface obj = (JSONRecordInterface) Type.forName(entityVersions.get(entity)).newInstance();
  17. jsonRecords.add(obj.returnStructure(entity, action, recordId));
  18. }
  19. return JSON.serialize(jsonRecords);
  20. }
  21.  
  22.  
  23. }
Add Comment
Please, Sign In to add comment