Tuesday, April 7, 2015

Geolocation Custom Field In Salesforce

The geolocation custom field allows you to create a field that identifies a location by its latitude and longitude. You can then use the geolocation field with the DISTANCE and GEOLOCATION formula functions to calculate distances between locations.

I would like to show you how we can update Geolocation field in Salesforce. It's slightly different from other fields, see it below:

Object Name: MyObject
Field Name: Geolocation__c;

To update Geolocation__c use below steps:

MyObject myObj = new MyObject(id=oid);
//here lat is a string
myObj.Geolocation__latitude__s = Decimal.valueOf(lat);
//here lng is a string
                myObj.Geolocation__longitude__s = Decimal.valueOf(lng);
update myObj;

Thanks.