Created
June 21, 2019 03:38
-
-
Save ketan-benegal/d5619a8eefaa56b0d29bd4ff549e24a1 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
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