Created
March 11, 2016 03:10
-
-
Save krystiancharubin/450ac31b78ee702cf11a to your computer and use it in GitHub Desktop.
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
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