Last active
July 8, 2021 23:26
-
-
Save jason-den/6e15fb56eda401a65f4c095a532d100d to your computer and use it in GitHub Desktop.
Get required fields from a given object. Code is supposed to execute as anonymous code in SF developer console
This file contains hidden or 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
string objectName = 'Assessment__c'; // Usage: change the object name here | |
Map<String, Schema.SObjectType> gdesc = Schema.getGlobalDescribe(); | |
Sobject objectt = gdesc.get(objectName).newSObject(); | |
Schema.DescribeSObjectResult r = objectt.getSObjectType().getDescribe(); | |
Map<String,Schema.SObjectField> M = r.fields.getMap(); | |
for(String fieldName : M.keySet()) { | |
Schema.SObjectField field = M.get(fieldName); | |
Schema.DescribeFieldResult F = field.getDescribe(); | |
Boolean isFieldreq = F.isCreateable() && !F.isNillable() && !F.isDefaultedOnCreate(); | |
if (isFieldreq) { | |
System.debug(fieldName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment