The CRMFusion company makes powerful Salesforce-record-editing software called DemandTools.
Below are some screenshots of setting up its "MassImpact" (single-table-editing) module to do a job equivalent to running an "UPDATE...SET...WHERE" DML SQL statement against a traditional database, for data cleansing within a specific single table.
For example, to turn all values of table Contact, field Home_Phone__c that are filled with nothing but 10 digits in a row, no punctuation, into a properly formatted US phone number, you might traditionally use the following Oracle-database-friendly DML SQL:
UPDATE Contact
SET Home_Phone__c = REGEXP_REPLACE(Home_Phone__c,'^(\d{3})(\d{3})(\d{4})$','(\1) \2-\3')
WHERE REGEXP_LIKE(Home_Phone__c,'^(\d{3})(\d{3})(\d{4})$')
In DemandTools, you would set up a MassImpact "scenario" as follows:
- Step 1: Tell DemandTools that you want to operate on the "Contact" object/table, and say which fields you want to be able to see the values of while you screen go/no-go on potential updates in the 3rd step.
- Step 2: Tell DemandTools that you want to potentially-update all records where "Home_Phone__c" isn't null (unfortunately, you can't use a regular expression in the "WHERE" with DemandTools – but step 3 has some dummy-proofing to get around too wide a selection),
and say that you want to propose a parentheses-and-dashes-formatted replacement value for any of the returned values that consist of nothing but a string of 10 bare digits in Home_Phone__c.
- Step 3: Ensure that you aren't pushing "UPDATE" calls for any records where there is no change to the value of Home_Phone__c, or where the new value of Home_Phone__c would be blank,
and skim the records to make sure your logic is doing what you thought it would,
and click "Update Records."
P.S. Just for geekiness, and to compare ease of use, here's some "Execute Anonymous" Salesforce Apex code along the same idea.
(Note: not tested at scale. Depending on your trigger/workflow/process builder load, might not actually work since it probably all runs in 1 "execution context" of post-DML CPU usage "governor limits," whereas DemandTools will run in truly separate "execution contexts" per 200 records to UPDATE.)
Map<Integer, List<Contact>> csToUpdate = new Map<Integer, List<Contact>>(); Integer csToUpdateCount = 0; Integer currentBatch = 0; List<Contact> cs = [SELECT Phone FROM Contact WHERE Phone <> null]; Pattern p = Pattern.compile('^(\\d{3})(\\d{3})(\\d{4})$'); for (Contact c : cs) { Matcher m = p.matcher(c.Phone); if(m.matches() == true) { csToUpdateCount++; currentBatch = (csToUpdateCount/200)+1; if (!csToUpdate.containsKey(currentBatch)) { csToUpdate.put(currentBatch, new List<Contact>()); } c.Phone = m.replaceFirst('($1) $2-$3'); (csToUpdate.get(currentBatch)).add(c); } } if (csToUpdate.size() > 0) { for (List<Contact> csToU : csToUpdate.values()) { UPDATE csToU; } }
No comments:
Post a Comment