Newer Version Available

This content describes an older version of this product. View Latest

Get the Geographical Coordinates of Addresses in Batch

The BatchGeocode() Apex method takes addresses and returns their geographical coordinates and formatted addresses.

Signature

Where,
  • maps is the namespace that's available after you install Salesforce Maps.
  • API is the class that contains the global methods exposed to developers.
  • BatchGeocode() is the method.

API Call Allocations

  • For geocoding, submit up to 120 requests per minute.
  • Send batches of up to 50 addresses per request.

Sample Code

This code returns the geographical coordinates of the White House and Washington Monument. The output also returns the formatted address and adds missing information, such as postal code and country, if available.

If you invoke methods within a flow, process builder, or trigger, do one of the following to avoid uncommitted work errors.

  • Call the methods through a future method
  • Call the methods as queueable

Different processes refresh the token, such as plotting a route or schedule. The refresh process is almost immediate after each qualifying action occurs.

Warning

Input Format of an Address

Example

Sample Response

Although the return value is an Apex Map<String, Object> object, this JSON response illustrates the essential data you receive in the resulting map.

If you invoke this method within a flow, process builder, or trigger and want to use the data from the JSON response, implement logic to retrieve that data. For example, you want to save the latitude and longitude coordinates from the JSON response to your records.

Responses include geocoding confidence scores based on address accuracy and completeness. For example, addresses missing city and state information result in scores lower than 100. Success results can include:
  • False, which indicates no match.
  • Partial, which indicates scores less than 100.
  • Full, which indicates scores of 100.

Sample Error Response

If you submit improperly created requests, expect a response similar to this.