Skip to content

Instantly share code, notes, and snippets.

@krystiancharubin
Created March 11, 2016 03:10
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 krystiancharubin/450ac31b78ee702cf11a to your computer and use it in GitHub Desktop.
Save krystiancharubin/450ac31b78ee702cf11a to your computer and use it in GitHub Desktop.
private static Map < String, List < String >> findEmaiLFields() {
Map < String, List < String >> soEmailFieldMap = new Map < String, List < String >> ();
// Iterate over all SObjects
for (SObjectType soType: Schema.getGlobalDescribe().values()) {
DescribeSObjectResult soDescribe = soType.getDescribe();
// Skip objects we cannot query or update
if (!soDescribe.isQueryable() || !soDescribe.isUpdateable()) continue;
String objectTypeName = soDescribe.getName();
// Iterate over all fields found on a given SObject
for (SObjectField soField: soDescribe.fields.getMap().values()) {
DescribeFieldResult field = soField.getDescribe();
// Skip non Email type fields
if (field.getType() != Schema.DisplayType.EMAIL) continue;
// Skip emails that cannot be filtered on
if (!field.isFilterable()) continue;
// Collect all Email fields found
if (soEmailFieldMap.containsKey(objectTypeName)) {
soEmailFieldMap.get(objectTypeName).add(field.getName());
} else {
soEmailFieldMap.put(objectTypeName, new List < String > {
field.getName()
});
}
}
}
return soEmailFieldMap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment