Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Class to generate a JSON body
- public class generateBodyClass {
- public String getRequestBody(List<Element__c> elementRecords) {
- List<JSONRecordInterface> jsonRecords = new List<JSONRecordInterface>();
- for ( Element__c rec : elementRecords) {
- String action = rec.Action__c;
- String entity = rec.Object_Name__c;
- String recordId = rec.Record_Id__c;
- List<EntityVersions__mdt> mappings = [SELECT DeveloperName, version__c FROM EntityVersions__mdt];
- Map<String, String> entityVersions = new Map<String, String>();
- for(EntityVersions__mdt mdt : mappings) {
- entityVersions.put(mdt.DeveloperName, mdt.version__c);
- }
- JSONRecordInterface obj = (JSONRecordInterface) Type.forName(entityVersions.get(entity)).newInstance();
- jsonRecords.add(obj.returnStructure(entity, action, recordId));
- }
- return JSON.serialize(jsonRecords);
- }
- }
Add Comment
Please, Sign In to add comment