Each of these methods is also equivalent to a read-only property. For each getter method, you can access the property using dot notation. For example, myAddress.getCity() is equivalent to myAddress.city.
You can’t use dot notation to access compound fields’ subfields directly on the parent field. Instead, assign the parent field to a variable of type Address, and then access its components. For example, to access the City field in myAccount.BillingAddress, do the following:
Address addr = myAccount.BillingAddress;
String acctCity = addr.City;
// Select and access Address fields. // Call the getDistance() method in different ways. Account[] records = [SELECT id, BillingAddress FROM Account LIMIT 10]; for(Account acct : records) { Address addr = acct.BillingAddress; Double lat = addr.latitude; Double lon = addr.longitude; Location loc1 = Location.newInstance(30.1944,-97.6682); Double apexDist1 = addr.getDistance(loc1, 'mi'); Double apexDist2 = loc1.getDistance(addr, 'mi'); System.assertEquals(apexDist1, apexDist2); Double apexDist3 = Location.getDistance(addr, loc1, 'mi'); System.assertEquals(apexDist2, apexDist3); }
The following are methods for Address.
public String getCountryCode()
Type: String
public Double getDistance(Location toLocation, String unit)
Type: Double
public String getStateCode()
Type: String