-
Notifications
You must be signed in to change notification settings - Fork 6
Chapter 5 : Setting Up Autocomplete
Setting Up Auto completion and Immediate Verification on Insert and Edit of records
n this section you will learn to configure the autocomplete feature in your Salesforce org. This feature is provided free with the app, but needs to be configured. SmartyStreets does not charge you for API calls when you use this, but when you press the “Save” button, it then sends a regular verification call to SmartyStreets, and this one is charged. As with the previous steps, we need to switch to the “Setup” area.
- Ensure that you have completed the Enabling Autocomplete section in Chapter 2 to set up the web key in the configuration page. This will open up the SmartyStreets Autocomplete API to allow processing your addresses. Note that you may need to do this in any Sandbox as well as in your Production org.
- Next, for the object that you want to set up, you will need to look at the layouts that are being used, and for each one, please ensure that it contains a section called “Address Information” with the address field(s) inside of it.
-
Finally, make sure that the address you want to use with Autocomplete is set up in the configuration page. If you are not sure, go to Setup App Packeging Installed Packages Address Verification Configure, and click on the “Manage Addresses” tab. The address must be listed here. If not, then it must be added.
a. Also, the Country field, as well as the required fields must be populated on the address record. Note that only US addresses are supported at this time, but the Country field must still be available in order for it to work. b. You can turn on the Street 2 field by populating this field and also turning on the “Use Street 2 with Autocomplete” feature at the bottom of the address configuration.
c. You can enforce a correct address by removing the “Use as Is” button when saving, by turning on the “Stop record creation on bad addresses (Autocomplete only)” feature also towards the bottom of the address configuration. Once these steps are done, you are ready to continue, depending on if you are on Classic or Lighting. Lightning Experience Configuration -
In Lightning, go to Setup -> Object Manager and then go to the object where you want to set Autocomplete up.
-
Select "Buttons Links and Actions" and edit either the standard "New" or "Edit" actions, depending on if you want to set it up for Inserts or Edits, or both.
-
From the override section, update the "Lightning Experience Override" item and select "smartystreets:AutoCompleteNew" if you are doing the "New" action, or "smartystreets:AutoCompleteEdit" if you are doing the "Edit" action.
-
Now, wait 10 seconds, and then go back to Salesforce, to the tab of the object where you set it up, and click the "New" button (or go to an existing record and press the "Edit" button). You might have to refresh the page, and do it a couple times, because sometimes Lightning takes a bit to refresh the options. But once you press the button, and scroll down to the address section, you will notice it looks a bit different. And when you start typing into the Street, you will see a dropdown.
Please note that once you start using custom edit pages you are entering a realm where you will have more administration than is typically needed in a Salesforce environment. Usually if you want to make a change to the layout like add or remove a field, you just have to click the "Edit Layout" link and make the change. However, once you have implemented this, you will have two additional steps:
- You will need to re-create the edit page by clicking on the "Create Edit Page" link (you might need to add this link to your layout first). This is shown in steps 7-11 below.
- You will need to give users access to this page again by updating the security for it. This is shown in steps 12-14 below. All of the JavaScript code referenced in the pages below can be found in the "js" folder in our GitHub repository:
| GitHub.com Address Verification Sample Code Repository |
|---|
| https://github.com/ToAFinish/addressverification |
- The second thing that we need to do is create a JavaScript link that will be used to create our edit page. We will assume in these instructions that we are creating it for Leads, but the instructions can be carried out also for Contacts or Accounts, by tweaking them slightly.
- Go to our GitHub repository. Click on the "create_lead_edit_page" page and copy all of the code to the clipboard. Note that when copying the code, do not include the line numbers. Start where the code starts at the top of line 1 (with "{!REQUIRED...") and go all the way to the last line.
- Note: If you are working on Accounts, there is one special requirement for Person Accounts. The regular “create_account_edit_page” will not work for Person Accounts, so you will need to also install the “create_person_account_edit_page” in that case.
- Go back to Salesforce and go to Setup -> Customize -> Leads -> "Buttons, Links and Actions" and click on the "New Button or Link" button.
- In the create button page, select the following: a) Label = "Create Edit Page" (you can change this if you wish) b) Display Type = "Detail Page Link" (you can change this to Detail Page Button if you wish) c) Behavior = "Execute JavaScript" d) Content Source = "OnClick JavaScript"
- In the body of the button, past the code you copied to the clipboard in step #2. Save and press "OK".
You have now created the link and you can add it to the Lead Layout so that you can use it. Just one quick question, though...

