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 getGeocodeAccuracy()
Type: String
The getGeocodeAccuracy() return value tells you more about the location at a latitude and longitude for a given address. For example, Zip means the latitude and longitude point to the center of the zip code area, in case a match for an exact street address can’t be found.
Accuracy Value | Description |
---|---|
Address | In the same building |
NearAddress | Near the address |
Block | Midway point of the block |
Street | Midway point of the street |
ExtendedZip | Center of the extended zip code area |
Zip | Center of the zip code area |
Neighborhood | Center of the neighborhood |
City | Center of the city |
County | Center of the county |
State | Center of the state |
Unknown | No match for the address was found |
Person accounts are not supported.
public String getStateCode()
Type: String