Geolocation Custom Field in Apex Class with Test Class
- subhashrdssv
- Dec 23, 2015
- 1 min read
Geolocation is one of the field in Salesforce which allows to identify locations using the Longitude and Latitude. By using the two of these fields, you can calculate the distance between the those two locations. While creating the field in the required object (in my case, i choose Account Object), You can choose any checkbox that how you want to fill the latitude and longitude (i.e., either on Decimal or Degrees,Minutes,Seconds). Let's see how to call this field in apex class.
Example of Apex class:
Public class AccountCreation{
Public void InsertMethod(){
Account acc = new Account();
acc.Name = 'My First Account';
acc.Location__Latitude__s = 13.0429;
acc.Location__Longitude__s = 80.2739;
(Give any other fields required....)
insert acc;
}
}
Test Class for above Apex Class:
@isTest
Public class AccountCreationTestClass{
static testmethod void InsertMethod(){
Account acc = new Account();
acc.Name = 'Test Class 1';
acc.Location__Latitude__s = 45;
acc.Location__Longitude__s = 45;
(Give any values for the fields that have given in above apex class....)
test.startTest();
insert acc;
test.stopTest();
}
}
Comments