Last active
December 12, 2016 20:02
-
-
Save nithesh1992/8a2348fb6797b8c823ce06c2202546b6 to your computer and use it in GitHub Desktop.
utils class to get a list of all fields of an object, all required fields of an object etc... and more to come
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
public class metaDataUtils { | |
public static Map<String, Schema.DescribeFieldResult> getFieldMetaData(String obj) { | |
Map<String,Schema.DescribeFieldResult> finalMap = new Map<String, Schema.DescribeFieldResult>(); | |
Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(obj).getDescribe().fields.getMap(); | |
// getting a specific object fields | |
for(String fieldName: objectFields.keySet()){ | |
finalMap.put(fieldName, objectFields.get(fieldName).getDescribe()); | |
} | |
return finalMap; | |
} | |
public static List<String> getRequiredFields(String obj){ | |
List<String> requiredFields = new List<String>(); | |
Map<String,Schema.DescribeFieldResult> finalMap = getFieldMetaData(obj); | |
for(String fr: finalMap.keySet()){ | |
if(!finalMap.get(fr).isNillable()){ | |
requiredFields.add(fr); | |
} | |
} | |
return requiredFields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment