Any marker you see on Map is always represented by 2 things i.e. Latitude and Longitude. Till Summer'16 it has been a challenge to geocode Salesforce addresses automatically so that they are ready to plot. Many have used third party APIs and Scheduled Batches to process Account/Contact/Lead records but trust me that was all time eating your API limits.
So, what is the surprise! Salesforce have released a feature in Summer'16 by which your Account/Contact/Lead records can be auto geocoded. This feature uses Data.com in back end but you don't need Data.com license for activation of auto geocoding feature. You just need to setup cleaning rules and you are good to go. So, precisely following standard Address fields can be auto geocoded based on any changes to below address fields.
For learning "How to setup cleaning rules" kindly read and follow below link:
Set Up Geocode Clean Rules
So, what is the surprise! Salesforce have released a feature in Summer'16 by which your Account/Contact/Lead records can be auto geocoded. This feature uses Data.com in back end but you don't need Data.com license for activation of auto geocoding feature. You just need to setup cleaning rules and you are good to go. So, precisely following standard Address fields can be auto geocoded based on any changes to below address fields.
- Billing Address on Account
- Shipping Address on Account
- Mailing Address on Contact
- Address on Lead
For learning "How to setup cleaning rules" kindly read and follow below link:
Set Up Geocode Clean Rules
Which fields store Lat/Lon pair in each of the objects above:
- Account Billing Address Geocode Fields: BillingLatitude, BillingLongitude and BillingGeocodeAccuracy
- Account Shipping Address Geocode Fields: ShippingLatitude, ShippingLongitude and ShippingGeocodeAccuracy
- Contact Mailing Address Geocode Fields: MailingLatitude, MailingLongitude and MailingGeocodeAccuracy
- Lead Address Geocode Fields: Latitude, Longitude and GeocodeAccuracy
What happens when Geocoding happens:
- Respective Latitude and Longitude fields are overwritten.
- SystemModStamp field is always updated. You need to review integrations which use this fields as criteria for qualification of records to get processed.
- By default, LastModifiedDate and LastModifiedById fields are not updated. You can change this behavior when you set up your geocode clean rules.
How to use this feature for business:
- You can use this to plot all your leads to understand how is the flow of inquiries per territory
- You can visualize your customer base on map territory wise
- You can start new campaigns to build your brand in new territories where you don't see much of your existence
- This can also be useful for plotting customers for Sales Reps/Marketing Reps
- Field Service can be another application of same
Sample code to try:
public class PlotLeads {
public List<Leads> lLeads {get; set;}
private String unitOfMeasure = 'mi';
public PlotLeads() {
//Fetching all Leads in 20 miles radius from my company HQ
lLeads = [SELECT Id, FirstName, LastName, Latitude, Longitude
FROM Lead
WHERE DISTANCE(Address, GEOLOCATION(35.273,-115.130), :unitOfMeasure) < 20
ORDER BY DISTANCE(Address, GEOLOCATION(35.273,-115.130), :unitOfMeasure)];
}
}