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