---
schema_version: "1"
id: f98c3df0bc339a19771c3995ad518354f19455af8e04c78f1fb3b4afb861cf05
title: Address Compound Fields
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/object_reference/compound_fields_address.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields_address.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: edde5b0fb8d5123007b1edcb580a36a2bc2f95db798e5e45d218cbdabd687b47
description: Standard addresses—addresses built into standard objects in Salesforce—are accessible in the SOAP API and REST API as an Address, a structured compound data type, as well as individual address elements. If you enabled Custom Address Fields, you can also add custom fields that mimic the standard address field behavior.
---
# Address Compound Fields

Standard addresses—addresses built into standard objects in Salesforce—are accessible in the SOAP API and REST API as an Address, a structured compound data type, as well as individual address elements. If you enabled Custom Address Fields, you can also add custom fields that mimic the standard address field behavior.

The Address type extends the Location type, the data type used for compound geolocation fields. Using API 30.0 and later, standard addresses are available in the SOAP and REST APIs as a compound field of type Address, a structured data type that combines these fields.

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d8855e59">Field</th>

              <th class="featureTableHeader  " id="d8855e62">Type</th>

              <th class="featureTableHeader  " id="d8855e65">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">Accuracy</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">picklist</td>

              <td class="entry" headers="d8855e65" data-title="Description">Accuracy level of the geocode for the address. For example, this
                field is known as <span class="keyword parmname">MailingGeocodeAccuracy</span> on
                Contact.</td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">City</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">string</td>

              <td class="entry" headers="d8855e65" data-title="Description">The city component of the address. For example, this field is
                known as <span class="keyword parmname">MailingCity</span> on Contact.</td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">Country</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">string</td>

              <td class="entry" headers="d8855e65" data-title="Description">The country component of the address. For example, this field is
                known as <span class="keyword parmname">MailingCountry</span> on Contact.</td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">CountryCode</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">picklist</td>

              <td class="entry" headers="d8855e65" data-title="Description">The ISO country code for the address. For example, this field is
                known as <span class="keyword parmname">MailingCountryCode</span> on Contact.<p dir="ltr" class="p">For Standard Address Fields,
                  <span class="keyword parmname">CountryCode</span> is only available when
                  state and country/territory picklists are enabled in your
                  organization.
                </p>
                <p dir="ltr" class="p">For Custom Address Fields,
                  <span class="keyword parmname">CountryCode</span> is always available,
                  whether or not state and country/territory picklists are enabled
                  in your organization.
                </p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">Latitude</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">double</td>

              <td class="entry" headers="d8855e65" data-title="Description">Used with <span class="keyword parmname">Longitude</span> to specify the precise
                geolocation of the address. For example, this field is known as
                <span class="keyword parmname">MailingLatitude</span> on Contact.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">Longitude</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">double</td>

              <td class="entry" headers="d8855e65" data-title="Description">Used with <span class="keyword parmname">Latitude</span> to specify the precise
                geolocation of the address. For example, this field is known as
                <span class="keyword parmname">MailingLongitude</span> on Contact.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">PostalCode</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">string</td>

              <td class="entry" headers="d8855e65" data-title="Description">The postal code for the address. For example, this field is known
                as <span class="keyword parmname">MailingPostalCode</span> on Contact.</td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">State</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">string</td>

              <td class="entry" headers="d8855e65" data-title="Description">The state component of the address. For example, this field is
                known as <span class="keyword parmname">MailingState</span> on Contact.</td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">StateCode</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">picklist</td>

              <td class="entry" headers="d8855e65" data-title="Description">The ISO state code for the address. For example, this field is
                known as <span class="keyword parmname">MailingStateCode</span> on Contact. <p dir="ltr" class="p">
                  <span class="keyword parmname">StateCode</span> is available only when state
                  and country/territory picklists are enabled in your
                  organization.
                </p>
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d8855e59" data-title="Field"><span class="keyword parmname">Street</span></td>

              <td class="entry" headers="d8855e62" data-title="Type">textarea</td>

              <td class="entry" headers="d8855e65" data-title="Description">The street component of the address. For example, this field is
                known as <span class="keyword parmname">MailingStreet</span> on Contact.</td>

            </tr>

          </tbody>

        </table>

Address fields are provided on many standard objects, such as Account, Contact, Quote, and User. Some objects provide fields for multiple addresses. For example, Account provides four different addresses. In this case, address field names are prefixed with the type of address, for example, BillingAddress and ShippingAddress.

![Note](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/images/icon_note.png)

#### Note

Standard address compound fields are read-only, and are only accessible using the SOAP and REST APIs. To learn about the limitations of compound fields, see [Compound Field Considerations and Limitations](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields_limitations.htm "Address and geolocation compound fields are convenient and result in more concise, clear code. Here are some things to consider when using them in your apps.").

When an address is geocoded, its latitude and longitude fields are populated with coordinates. A related geolocation field is also populated. Typically, geocoding service providers geocode addresses, and rate the accuracy of the geocodes.

The accuracy subfield GeocodeAccuracy stores the accuracy data for a geocoded location. External geolocation apps can get the accuracy level of a geocoded address via the API. When you retrieve an address via the API, any accuracy data is included. You can also retrieve the accuracy information by itself, if needed.

Like its parent, the compound Address field, the GeocodeAccuracy field is only available for standard address fields on standard objects.

## Custom Address Fields

If you enabled Custom Address Fields, the Address field type is available in Object Manager when you add a custom field. Custom address fields mimic the behavior or standard address fields with some limitations.

For more information, see the [Custom Address Fields Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.264.0.caf_dev_guide.meta/caf_dev_guide/caf_dev_guide.htm).

## Retrieving Compound Address Fields

Using compound fields can simplify code that works with addresses, especially for SOQL queries. SOQL SELECT clauses can reference addresses directly, instead of all of the individual component fields.

SELECT Name, BillingAddress
FROM Account

To write a SOQL query that’s compatible with API versions earlier than 30.0, as well as API 30.0 and later, use the individual fields:

SELECT Name, BillingStreet, BillingCity, BillingState, BillingPostalCode,
       BillingCountry, BillingLatitude, BillingLongitude
FROM Account

Compound address field values are returned as a structured data type, Address. Code that works with compound address fields must reference the individual components of the returned value. See the code sample below.

## Retrieve a Standard Address Compound Field with the SOAP API

This Java method uses the Salesforce SOAP API to retrieve and display the Mailing Address for a list of contacts.

// Modified version of code in the SOAP API QuickStart
private void querySample() {
    String soqlQuery = "SELECT FirstName, LastName, MailingAddress FROM Contact";
    try {
        QueryResult qr = connection.query(soqlQuery);
        boolean done = false;

        if (qr.getSize() > 0) {
            System.out.println("\\nLogged-in user can see "
              + qr.getRecords().length + " contact records.");

            while (!done) {
                System.out.println("");
                SObject\[\] records = qr.getRecords();
                for (int i = 0; i < records.length; ++i) {
                    Contact con = (Contact) records\[i\];
                    String fName = con.getFirstName();
                    String lName = con.getLastName();

                    // Access the compound address field MailingAddress
                    Address addr = (Address) con.getMailingAddress();
                    String streetAddr = "";
                    if (null != addr) streetAddr = addr.getStreet();

                    if (fName == null) {
                        System.out.println("Contact " + (i + 1) + ": " + lName +
                            " -- " + streetAddr);
                    } else {
                        System.out.println("Contact " + (i + 1) + ": " + fName +
                            " " + lName +
                            " -- " + streetAddr);
                    }
                }

                if (qr.isDone()) {
                    done = true;
                } else {
                    qr = connection.queryMore(qr.getQueryLocator());
                }
            }
        } else {
            System.out.println("No records found.");
        }
    } catch (ConnectionException ce) {
        ce.printStackTrace();
    }
}

## Using Compound Address Fields as Locations

Compound address fields include latitude and longitude fields. Address fields can be used as locations in SOQL WHERE and ORDER BY clauses. For example, here’s a SOQL query that uses the GEOLOCATION function to retrieve the 10 accounts closest to San Francisco.

SELECT Id, Name, BillingAddress
FROM Account
WHERE DISTANCE(BillingAddress, GEOLOCATION(37.775,-122.418), 'mi') < 20 
ORDER BY DISTANCE(BillingAddress, GEOLOCATION(37.775,-122.418), 'mi')
LIMIT 10

![Note](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/images/icon_note.png)

#### Note

In Developer, Professional, Enterprise, Unlimited, and Performance editions, Salesforce can automatically add or update geolocation fields for Account, Contact, Lead, and WorkOrder records. To use this feature, your administrator must enable the geo data integration rule for each object. For all other objects and editions, set values for latitude and longitude by using SOQL, SOAP or REST API, or a geocoding service. You can then use address fields as locatable values. To find geocoding services, search AppExchange.