Last active
August 29, 2015 14:17
-
-
Save b-wilder/0cd489bd8f1025be6068 to your computer and use it in GitHub Desktop.
Get all creatable fields for any SObject (Apex, Salesforce)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static set<string> getCreatableFields(Schema.SObjectType objectType) | |
{ | |
Map<String, Schema.SObjectField> fMap = objectType.getDescribe().Fields.getMap(); | |
set<string> creatableFields = new set<string>(); | |
if (fMap != null){ | |
for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft) | |
Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd) | |
if (fd.isUpdateable()&&!fd.isUnique()){ // field is creatable | |
creatableFields.add(fd.getName()); | |
} | |
} | |
} | |
return creatableFields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment