Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public static Map<String,String> getCustomFields(String objName){
  2. Map<String,String> customFields = new Map<String,String>();
  3. SObjectType accountType = Schema.getGlobalDescribe().get(objName);
  4. Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();
  5. for(String fld : mfields.keySet()){
  6. if(fld.contains('__c'))
  7. customFields.put(fld, mfields.get(fld).getDescribe().getName());
  8. }
  9. System.debug('customFields => '+customFields);
  10. return customFields;
  11. }
  12.  
  13. poc.getCustomFields('Account'); // to get account custom fields
  14.  
  15. public static List<String> getCustomFields(String apiName) {
  16. SObjectType objType = ((SObject) (Type.forName('Schema.' + apiName).newInstance())).getSObjectType();
  17. Map<String, SObjectField> fieldsByName = objType.getDescribe().fields.getMap();
  18. List<String> customFields = new List<String>();
  19.  
  20. for (SObjectField field : fieldsByName.values()) {
  21. if (field.isCustom()) {
  22. customFields.add(field.getDescribe().getName());
  23. }
  24. }
  25.  
  26. System.debug('customFields => ' + customFields);
  27.  
  28. return customFields;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement