Easy Geocoding in Summer ’16

In the past, if you’ve wanted to geocode (that is, to store the longitude and latitude for) address fields in Salesforce, you’ve probably had to go to great pains to do so. In fact, in a Salesforce webinar that Kartik Viswanadha and I recently presented, we discussed several techniques for using Asynchronous Apex with callouts to an external web service to perform geocoding. Fortunately, in Summer ’16, geocoding has gotten a whole lot easier, at least for Salesforce’s standard Address fields.

The new geocoding functionality uses a Data.com feature, but you don’t need to have a Data.com license to use it.

Data.com Clean Rules for Geocoding
Data.com Clean Rules

From Setup, enter “Clean Rules”

in the Quick Find box and select it. Review and activate any of the four pre-defined Geocode Clean Rules for:

  • Account Billing Address
  • Account Shipping Address
  • Contact Mailing Address
  • Lead Address

(Note: this feature is not supported for Person Accounts.)

These predefined rules specify the details of the geocoding action for each of the four standard Address fields. If you select “Clean all records when this rule is activated or saved,” Salesforce will automatically geocode your existing records.

When Salesforce geocodes your address fields, it places the results in the corresponding standard Longitude and Latitude fields. For some reason, Salesforce doesn’t make these fields available to be placed on a page layout. However, you can define formula fields that expose the values of the standard Longitude and Latitude fields, and then place your formula fields on the page layout.

A Few Notes for Developers when Geocoding:

  • The geocoding happens asynchronously. For example, if you query an Account in the same transaction in which you create it, you won’t see the Longitude/Latitude information filled in.
  • When the Longitude/Latitude does get populated, Salesforce fires triggers on the object only if the Clean Rule’s “Bypass Triggers” checkbox is unchecked. If you want to take some action when a record’s Longitude/Latitude change, you can put that action into the trigger (or a workflow rule, for that matter), but don’t forget to configure the Clean Rule to not bypass triggers or workflow.

With Summer ’16, geocoding standard Address fields is now easy and painless, and with this in place, you’ll always know where your Accounts, Contacts, and Leads are!

 

MJ Kahn, SVP of Technology at OpFocus

about the author

MJ Kahn

At OpFocus, MJ architects and constructs solutions that would impress the builders of the pyramids. She solves technical puzzles that would frustrate daVinci. She leaps tall buildings (like the new Salesforce tower) in a single bound.

Well ok, maybe she doesn’t. But she does help lead an amazing team of smart, talented, and dedicated consultants who do. MJ’s job at OpFocus is provide technical leadership and guidance to OpFocus clients and team members so that, working together, we can create innovative yet practical solutions to real-world business problems within the Salesforce ecosystem.

Prior to OpFocus, MJ built an extensive background in technology and has held a variety of development, consulting, and management positions at companies like Sybase, Vignette, and Honeywell, among others. In these roles, MJ’s focus was helping companies effectively and intelligently use technology to solve business problems. An Apex and Visualforce consultant since mid-2008, MJ has worked with scores of companies to help them understand and utilize platforms like Force.com to solve business issues and also guide them in developing their own AppExchange product offerings.