Created
June 21, 2019 03:53
-
-
Save ketan-benegal/62eae5b337223923fcbb0c0d718af91f 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 void cleanEmailFields(Map < String, List < String >> mSobjField) { | |
// Iterate through SObject->Email Fields | |
for (String sObjName: mSobjField.keySet()) { | |
// Build a list of all fields that need to be queried | |
List < String > lstEmailFields = mSobjField.get(sObjName); | |
// Generate a SOQL query to get records with non null emails | |
String soql = createSOQL(sObjName, lstEmailFields); | |
List < SObject > sObjRecords = new List < SObject > (); | |
// Iterate through SObject records | |
for (SObject sObjRecord: Database.query(soql)) { | |
// Iterate through email fields found on SObject and replace with dummy values | |
for (String strField: lstEmailFields) { | |
String strEmail = (String) sObjRecord.get(strField); | |
if (String.isEmpty(strEmail)) continue; | |
sObjRecord.put(strField, strEmail.replaceAll('\\W', '_') + '@invalid.invalid.co'); | |
} | |
sObjRecords.add(sObjRecord); | |
} | |
update sObjRecords; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment