Skip to content

Chapter 5 : Setting Up Autocomplete

Joseph Dindinger edited this page Dec 30, 2019 · 10 revisions

Setting Up Autocomplete

Setting Up Auto completion and Immediate Verification on Insert and Edit of records

I

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.

image

Initial Configuration

  1. 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.
  2. 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.

image

  1. 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 -> Apps -> Packaging -> 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

  1. In Lightning, go to Setup -> Object Manager and then go to the object where you want to set Autocomplete up.

  2. 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.

  3. 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.

  4. 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.

Classic Configuration

Important Note for Using Custom Edit Pages

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:

  1. 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.
  2. 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

Add the "Create Edit Page" Link

  1. 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.
  2. 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.
  1. Go back to Salesforce and go to Setup -> Customize -> Leads -> "Buttons, Links and Actions" and click on the "New Button or Link" button.
  2. 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"
  3. 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...

image

Does the object you are wanting to set up (e.g. Leads) use Record Types? In order to check: go to Setup -> Object Manager -> Leads -> Record Types, do you see any record types listed? If so, you will need to comment line #7 and uncomment line #9. Save. 7) Go to Setup -> Object Manager -> Leads -> Page Layouts

  1. IF you have more than one layout, you need to know which of the layouts are being used. Click on the "Page Layout Assignments" and make a note of which page layouts are used. For each one, you will need to do steps 9-14.

  2. Click "Edit" next to the Page Layout you want to modify

  3. Scroll down to the "Custom Links" section and click on the "Custom Links" list in the top toolkit. Drag down the "Create Edit Page" link into the "Custom Links" section. Save the Layout.

  4. Now go to a record of the type you just updated the layout for (e.g. Leads) and you will see the "Create Edit Page" link. Click this link to create the edit page. You will see it open up. You can Save or click "Cancel" if you wish.

Enabling the New Custom "Edit" Page for New Records

Now we need to do two steps in order to use the new page we created:

  1. First, to enable the new custom New page on record edits or inserts, please do the following. Go to Setup -> Object Manager -> Leads -> "Buttons, Links and Actions" and click the Edit link on the "New" label.

  2. Select the AV Lead Override (New/Edit) page and Save. Now, when you add a new Lead, the custom Edit page should display (if you have access to it through your profile).

  • Note: You can use this as well with the Edit page overwrite, but if you do so, inline editing will no longer work. See the next sub-section for how to use the new custom Edit page with existing records.

Enabling the New Custom “Edit” Page with Existing Records

This step will allow you to use the autocomplete edit page with existing records. Note that you can use the previous section to overwrite the “Edit” page, if you want, but doing that will remove the Inline Editing function that many users find useful in Salesforce. By creating a custom Edit button as explained in this section, you can maintain inline editing, while overwriting the main Edit page.

  1. Now we must create a button for our custom 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.

  2. Go back to Salesforce and go to Setup -> Object Manager -> Leads -> "Buttons, Links and Actions" and click on the "New Button or Link" button.

  3. In the create button page, select the following:

a) Label = " Edit (Autocomplete)" (you can change this if you wish)
b) Display Type = "Detail Page Button"
c) Behavior = "Display in existing window without sidebar or header"
d) Content Source = "Visualforce Page"
e) Content = “AV Lead Override (New/Edit)”

  1. Go back to Setup -> Object Manager-> Leads -> Page Layouts

  2. IF you have more than one layout, you need to know which of the layouts are being used. Click on the "Page Layout Assignments" and make a note of which page layouts are used. For each one, you will need to do steps 19-21.

  3. Click "Edit" next to the Page Layout you want to modify

  4. Scroll to the "Buttons" section and click on the "Buttons" list in the top toolkit. Drag down the "Edit" button into the "Custom Buttons" section. You may want to remove the standard “Edit” button as well. Save the Layout.

  5. Now go to a record of the type you just updated the layout for (e.g. Leads) and you will see the custom "Edit" button. Test and make sure it takes you to the new page.

After testing as the System Administrator, now deploy to users.

  1. We need to give everybody access to this new Edit page that was created. Go to Setup -> Custom Code -> VisualForce Pages.

  2. Find a page with a name starting with "AV" and then named with the object name followed by the record type name, or "Standard" if no record types exist. For example, for Leads, it would be "AV Lead Standard". Click the "Security" link next to this page.

  • Note: You might want to sort the list of VisualForce pages by the Last Modified Date so that the latest page created will be at the top .
  1. Move over as many profiles as you want from the "Available Profiles" to the "Enabled Profiles". If you only want some of your users to use the new edit page with auto-complete, then don't put their profile into the "Enabled Profiles". Save when done.

You will need to do the same steps 2-16 for the Account and Contact objects.

  • Please note that autocomplete is not currently available for custom objects in Classic (it works in Lightning). However, we would be happy to work with you to create custom autocomplete pages for your own object, or integrate with other page solutions you might be using. We have some starter code that could help you.

Autocomplete in a Flow

Newly released is the ability to verify one or more addresses in a step of a Flow. Either verifying an existing record, or verifying an address independently of any existing records.

image

All of the code to build the Lightning Components that work in the Flow, along with detailed instructions, can be found in the "flow" folder in our GitHub repository:

image

GitHub.com Address Verification Sample Code Repository
https://github.com/ToAFinish/addressverification

We hope you enjoy our Address Verification app for Salesforce! Please do let us know if you run into any issues by simply emailing [email protected] and asking any question. We're here to help!