Created
March 11, 2016 03:12
-
-
Save krystiancharubin/e737c573d0fcb1093a18 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 void processEmailFields(Map < String, List < String >> soEmailFieldMap) { | |
// Iterate over the SObject to Email Fields collection | |
for (String objectName: soEmailFieldMap.keySet()) { | |
// Get any specified conditionals | |
Map < String, Object > conditionals = new Map < String, Object > (); | |
if (objectConditionals.containsKey(objectName)) conditionals = objectConditionals.get(objectName); | |
// Build a list of all fields that need to be queried | |
List < String > emailFields = soEmailFieldMap.get(objectName); | |
List < String > fieldList = new List < String > (); | |
fieldList.addAll(emaiLFields); | |
fieldList.addAll(conditionals.keySet()); | |
// Generate a SOQL query to get records with non null emails | |
String soql = getSOQL(objectName, fieldList); | |
System.debug(soql); | |
List < SObject > records = new List < SObject > (); | |
// Iterate over queried SObject records | |
for (SObject record: Database.query(soql)) { | |
// Skip records that do not match specified conditons | |
if (!checkConditions(record, conditionals)) continue; | |
// Iterate over Email fields found on SObject and invalidate values | |
for (String field: emailFields) { | |
String email = (String) record.get(field); | |
if (String.isEmpty(email)) continue; | |
record.put(field, email.replaceAll('\\W', '_') + '@disabled.diabled'); | |
} | |
records.add(record); | |
} | |
System.debug(JSON.serializePretty(records)); | |
update records; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment