-
Notifications
You must be signed in to change notification settings - Fork 6
Chapter 4: Automation and Bulk Verification
What to do with existing records, or records that will be imported into Salesforce in bulk
n this section you will learn what you can do in order to clean up existing data in Salesforce, and how you can make sure that your data stays clean. In the previous section we explain how to let users verify individual addresses and in the next section, we get into the new Autocomplete feature, but here we discuss the back-up plan for all of this – what to do when a record is saved in Salesforce and is not perfectly clean.
If the amount of records you need to clean up is not huge, you might be able to clean them 200 at a time using our list view button. Even if the number of records is too large to do cleanup manually, it is always a good idea to configure the option in case you want to use it in the future.
You can set up a button to verify multiple addresses at one time from a standard Salesforce.com list. We will step through how to do it for Leads, but the process is very similar for Accounts and Contacts, and even custom objects.
From the list of available buttons, select the one called “Verify Selected Addresses” and press the -> arrow button. Next, press the Save button.
The button will now be available from any Lead list view. You can select as many records as you want, up to 100 and then press the Verify Selected Addresses.
- Please note several things when verifying multiple addresses at once:
- You will use up a SmartyStreets.com Address Lookup for every address. So, even though you verify 100 at a time, you are still charged for 100.
- If addresses are very long, sometimes Salesforce.com (not SmartyStreets) will choke on multiple verifications at once, and will show you an error. If that happens, please try selecting less addresses and trying again.
A button can also be added for multiple-record address validation for custom objects. Please follow these steps and you should be able to add the button fairly easily.
First, create a simple Visualforce page by going to Setup->App Setup->Develop->Visualforce pages, and press the “New” button. Then, paste the code below into the page area:
<apex:page
standardController="Object_Name __c"
extensions="smartystreets.VerifySelectedAddressesExt"
recordSetVar="leads"
sidebar="false"
showHeader="false">
<smartystreets:VerifyAddressesList
Controller="{!setCon}" />
</apex:page>
Replace the highlighted “Object_Name__c” with the API name of the custom or standard object.
- Note: Make sure to select the " Available for Lightning Experience, Lightning Communities, and the mobile app” option when creating the page, as this will allow it to appear in Lightning as well as Classic.
Next, go to the object you want to verify, and find the “Buttons, Links and Actions” section and then create a new button. Set it as a “List Button” with the “Display Checkboxes (for Multi-Record Selection)” option ON, and have the behavior “Display in Existing Window without sidebar or header.” Under the Content Source, select “Visualforce Page” and then select the page you created in the steps above.
Now, you will need to add this button to the search layout as shown at the beginning of this chapter, and you are good to go!
A word about JavaScript buttons. We still provide the code for JavaScript buttons in our repository. These can be used in Classic Salesforce, but are no longer recommended by Salesforce. If you are currently using Classic, it is OK to stay with them as they provide a somewhat faster experience, but our recommendation is to move to either a Lightning Component or a Visualforce page as described above.
Depending on the amount of records in Salesforce, and the ongoing process of ingesting new records into the org, many companies need an automated solution that will do the work for them in the background. Address Verification provides several options.
You can turn on automatic verifications via Trigger for the Lead, Account and Contact objects in Salesforce. This will automatically verify any addresses configured on these objects whenever they are imported or updated. This feature is easy to turn on:
- Go to Setup -> Apps -> Packaging -> Installed Packages and click on the Address Verification app. Once there, you can click the “Configure” button.
- In the Setup page, click the AUTOMATION tab, then select one or more of the “Automatically Verify” fields and press the “Save Settings” button. You can select Accounts, Contacts or Leads.
This will now turn on the automated verification for these objects.
- Note: Please keep in mind that Salesforce does not allow verifications to happen in real time when a record is being updated or created. The reason is that in order to verify the address, we are making a call out to SmartyStreets, and we are forced to make it in the background (asynchronous) instead of in real-time (synchronous). What this means is that if you create a record with the automated trigger turned on, you will first see the record is not verified, but if you refresh it after a couple seconds, you then see the verification completed. If this timing is a showstopper, please see the section on the advanced Autocomplete feature, where we overcome this issue, but add a little complexity to the process.
We are introducing a new feature which allows you to immediately verify addresses entered if they already exist in the system without having to make an API call and re-verify the same address again. This feature is very helpful if duplicate values are often entered into your org. For example, if multiple Leads with the same address are expected to be entered, you can often avoid re-validating the same address multiple times.
- Note that currently we have a few limitations for this new feature :
o This only works with triggers. Meaning when the verifications are automatic. If you click the “Verify Addresses” buttons or schedule a job to clean up all addresses, this feature is not used.
o Only addresses in the same object will be checked for existing verifications. So if you are creating a Lead and an Account with a verified address already exists, it will not see it.
o Only certain “critical” fields are copied to the new object, it is not completely populated with data the way a regular verification would.
o For organizations with a large amount of records, usually above 200,000 Accounts, Contacts or Leads, this may fail to work depending on several factors. If this is your case, please contact [email protected] so that we can work with you to see if you can use this feature.
- First, you will need to configure a “Clean Street” field for each address where you want to start using this feature. This is a field where a stripped down, “clean” version of your street address will be hosted. This is the field, along with City and State , which is used to find a match. On the MANAGE ADDRESSES tab in the Setup page, edit the appropriate addresses and set this field. Note that you might need to create these fields first. If so, make it Text (255).
- Next, switch to the AUTOMATION tab in the Setup page, and check the appropriate “Check for Existing…” field. Press the Save Settings button to turn the feature on.
- Finally, you might want to update your existing data to use this functionality. You don’t have to do this, but if you don’t, then it will only work with data moving forward. In order to clean all data, you can either re-validate all records, which might be costly, or you can run a script in the Developer Console to “clean” all of your data. Experienced administrators or developers should only attempt this last option. In the future we may have a button that will clean up your data for you, but for now, it is a manual process through code. Here is a sample that would clean 100 Lead records:
List<Lead> leadlist = [select Id, Street, CleanStreet__c
from Lead
where Street != null
and CleanStreet__c = null
and isConverted = false
limit 100];
for(Lead l:leadlist) {
l.CleanStreet__c = SmartyStreets.Clean.AddressCleanse(l.Street);
}
update leadlist;
The key function is SmartyStreets.Clean.AddressCleanse(). This function will clean any given street address and standardize it as needed by our function. Please do not hesitate to contact us using the [email protected] email address. We will be happy to talk this through with you and help you to get your data cleaned. In a future release, we expect to make it easy to do, but for now, it is an administrative function that isn’t easy. For custom objects or custom addresses, see the next two sections on how to set up your own trigger or process to do this same function yourself.
If you have a custom address outside of the Lead, Account and Contact objects and want automated address verification, you will need to either create a custom trigger, which is explained here, or else create a custom process, explained in the following section.
* Please note that triggers might be currently more reliable in the long run than processes, especially if bulk imports are intended for this object. It will be potentially more complicated to set up a trigger, but it might be worth it for the reliability achieved.
For triggers, first we must set up a couple helper classes. Note that this must be done in a sandbox, and then deployed into production. A production instance of Salesforce will not let you create classes or triggers directly, rather only through the sandbox process.
- Go to Setup -> Custom Code -> Apex Classes and click the New button.
- When you press the New button, a blank textbox will come up.
GitHub.com Address Verification Sample Code Repository |
---|
https://github.com/ToAFinish/addressverification |
- Paste the Apex code that you can find in the “class” folder on our GitHub.com repository, linked to below. The code from a file called ScheduleBatchOfficeAddressVerification, but before saving, you must modify the code a little in order to customize it for your particular custom object:
a. You can change the name of the Class.
b. Replace “Office__c” on line 7 with the API name of your object.
c. Save.
-
Once complete, go to Setup Object Manager Create Custom Objects. Once there, scroll down to the “Triggers” area and press the New button.
-
In the text area provided, fill in the code found in the “trigger” folder in our GitHub.com repository, see above. The file is called autoVerifyOfficeAddress and again, you will need to make several changes to the code before it will work:
a. You can change the name of the trigger
b. All instances of “Office__c” will need to be changed to match the API name of your selected object.
c. All field names may need to be changed, depending on what your fields are called: Street__c, City__c, State__c, Zip__c, AddressVerified__c and DoNotVerify__c are all found in the code and might need to be changed to the correct name.
d. If you changed the name of the Apex Class in step 3 above, you will need to change it here too.
- When finished, press the Save button, and the trigger is now ready to run every time a record is updated.
If you have a custom address outside of the Lead, Account and Contact objects and want automated address verification, you will need to either create a custom trigger, which is explained in the section prior, or an easier solution is to build out a process to handle the verification.
- Go to Setup -> Process Automation -> Process Builder and press the New button.
- Call the process what you will and then select “a record changes” under the The Process Starts When dropdown, and press the Save button.
- Now click on the “Add Object” area and select your custom object under the Object field, and then select “when a record is created or edited” under the Start the process selection. Click Save.
-
Now click the Add Criteria section on the left.
-
In the Add Criteria popup, you will need to fill out a few things. First, name it something like “Not Verified”. Next, you will need to add 5 conditions as shown below. Note that the field names will be different, depending on what you have called your fields:
Field | Operator | Type | Value |
---|---|---|---|
AddressVerified__c | Equals | Boolean | False |
Street__c | Does not equal | Global Contstant | $GlobalConstant.null |
City__c | Does not equal | Global Contstant | $GlobalConstant.null |
State__c | Does not equal | Global Contstant | $GlobalConstant.null |
Zip__c | Does not equal | Global Contstant | $GlobalConstant.null |
- Under the Conditions section, select “Customize the logic” and then enter the following, and then press the Save button:
-
Now click the Add Action link under the “IMMEDIATE ACTIONS” area. In the popup, select “Apex” as the Action Type, then give it a name, and select “smartystreets__AddressUpdateService” under the Apex Class.
-
Now, in the “Apex Variables” area, click the Add Row link. In the new row, select “recIdList” for the Field, “Reference” for the Type, and drill into the Value field and select the Record Id for your custom object.
- Now press the Activate button at the top of the page and you are ready to start testing. This process should validate the record in your custom object whenever you create or update a record that hasn’t been already verified.
- Please note that this same technique can be used to verify the standard objects (Leads, Contacts, Accounts) and could potentially also be used with different filters to meet specific business requirements – for example, if you want to verify an address only under certain conditions. Use the above steps as a guideline for how to set it up, but you are free to change it up to fit your process
If you do not want to have addresses verified via triggers or processes as shown in the sections above, you can also schedule a daily job that will verify all addresses that need it.
-
Go to Setup -> Apps -> Packaging -> Installed Packages and click on the Address Verification app. Once inside, click on the Configure button to take you to the setup page.
-
Click on the AUTOMATION tab and scroll down to the “Daily Scheduled Job” section. Here is where you can turn on this job. Most of it is self-explanatory, but a couple notes:
a. If you enter a value other than 0 in the expire validations > X days field, then any validations that were done prior to that number of days in the past will be re-validated when the job runs. This is helpful for organizations that must validate their addresses periodically.
b. You are able to also have an email sent to the current user when the job completes, IF it validated any addresses.
-
Press the Save Settings button to schedule the job. You can always press the Delete Schedule Job if you want it to stop. You are done!
-
If you prefer to run the job one time, you can press the Run This Job Now button.
You can turn off the Account, Contact and Lead triggers installed with our app. This is useful mostly for troubleshooting or before doing large data processing jobs where you want as little overhead as possible.
If you turn off these triggers permanently, you will probably want to re-create the following automation in the process builder, which is able to do both of these functions:
- Monitor address fields and whenever one of them is changed, uncheck (turn off) the appropriate “Address Verified” checkbox for the particular address, update the Address Return Code to “Changed” and perhaps also update the address footnotes. This will indicate that the address needs to be re-verified.
- Set up desired records to automatically verify if criteria like address field population, and “Address Verified” field being false. See Custom Object Process Verifications in Chapter 4, for a description of how to set this up.
You are able to store logs of the verifications you have performed. Please note that turning on this option might result in a lot of records being created in the Verification Logs object included with the app.
To see these logs, you first have to make sure that you have access to the object and all of the fields in the object. Once you do, you also need to make sure that the tab is not hidden for your profile. You will need to talk to your Salesforce administrator for both of those things. If you don’t have an administrator, please reach out to us at [email protected] and we can do it for you if you can provide us remote access.
Please explore our GitHub.com repository for ways that you can automate some of the address verification features within Salesforce.com. We may also have code that is not included in the public repository yet, so let us know if have any specific requirements and can’t find what you need. We cannot support this code for free, but please use it and contact us if you need technical assistance.