Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ketan-benegal/d5619a8eefaa56b0d29bd4ff549e24a1 to your computer and use it in GitHub Desktop.
Save ketan-benegal/d5619a8eefaa56b0d29bd4ff549e24a1 to your computer and use it in GitHub Desktop.
public static Map < String, List < String >> findAllEmaiLFields() {
Map < String, List < String >> mSObjEmailFields = new Map < String, List < String >> ();
// Iterate through all SObjects
for (SObjectType sObjType: Schema.getGlobalDescribe().values()) {
DescribeSObjectResult sObjDescribe = sObjType.getDescribe();
// Avoid objects that cannot be queried or updated.
if (!sObjDescribe.isQueryable() || !sObjDescribe.isUpdateable()) continue;
String sObjName = sObjDescribe.getName();
// Iterate through all fields
for (SObjectField sObjField: sObjDescribe.fields.getMap().values()) {
DescribeFieldResult sObjFld = sObjField.getDescribe();
// Consider only Email fields
if (sObjFld.getType() != Schema.DisplayType.EMAIL) continue;
if (!sObjFld.isFilterable()) continue;
// Add all Email fields in the map.
if (mSObjEmailFields.containsKey(sObjName)) {
mSObjEmailFields.get(sObjName).add(sObjFld.getName());
} else {
mSObjEmailFields.put(sObjName, new List < String > {
sObjFld.getName()
});
}
}
}
return mSObjEmailFields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment