Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Map<String,String> getCustomFields(String objName){
- Map<String,String> customFields = new Map<String,String>();
- SObjectType accountType = Schema.getGlobalDescribe().get(objName);
- Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();
- for(String fld : mfields.keySet()){
- if(fld.contains('__c'))
- customFields.put(fld, mfields.get(fld).getDescribe().getName());
- }
- System.debug('customFields => '+customFields);
- return customFields;
- }
- poc.getCustomFields('Account'); // to get account custom fields
- public static List<String> getCustomFields(String apiName) {
- SObjectType objType = ((SObject) (Type.forName('Schema.' + apiName).newInstance())).getSObjectType();
- Map<String, SObjectField> fieldsByName = objType.getDescribe().fields.getMap();
- List<String> customFields = new List<String>();
- for (SObjectField field : fieldsByName.values()) {
- if (field.isCustom()) {
- customFields.add(field.getDescribe().getName());
- }
- }
- System.debug('customFields => ' + customFields);
- return customFields;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement