Skip to content

Instantly share code, notes, and snippets.

@mpassovoy
Last active February 11, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpassovoy/c3861aa92a9ac5558c6997866621a9ab to your computer and use it in GitHub Desktop.
Save mpassovoy/c3861aa92a9ac5558c6997866621a9ab to your computer and use it in GitHub Desktop.
getListOfFields
public static Map<String,Object> getListOfFields(String sobjectType){
SObjectType objectType = Schema.getGlobalDescribe().get(sobjectType);
Map<String,Schema.SObjectField> mapObjectFields = objectType.getDescribe().fields.getMap();
Map<String,Object> fieldMap = new Map<String,Object>();
List<String> fieldNames = new List<String>();
for (String field : mapObjectFields.keySet()) {
Schema.DescribeFieldResult dr = mapObjectFields.get(field).getDescribe();
//Only add Custom, non-formula fields, non-auto number
if (dr.isCustom() && !dr.isCalculated() && !dr.isAutoNumber()) {
fieldNames.add(field);
fieldMap.put(field,null);
} else if (dr.isCreateable()) {
fieldNames.add(field);
fieldMap.put(field,null);
}
}
return fieldMap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment