New Spring ’15 Features: Mapping

The Spring ’15 release is upon us! As with every Salesforce release, it comes with a plethora of new features. One of the cooler aspects of the Spring ’15 release is the addition of some mapping functionality.

Standard Address Fields Show Google Maps

Records with standard address fields now display a Google Maps image of the address. This saves users time by letting them see where their contacts or accounts are located, instead of having to locate addresses in a separate browser tab.

On a record, go to the detail page to see the Google Maps image on the address field. To generate a map image, an address must include the street and city fields and either the state, postal code, or the country. If an address field is missing any of the required information, a map won’t display.

Address fields will now look like:

This feature also works in Salesforce1.

This functionality will be on by default. To disable it, go to Customize | Maps and Locations | Settings and uncheck Enable Maps and Location Services.

Limitations Changed for Geolocation Fields (Generally Available)

Geolocation fields, formerly available only as a beta release, are now generally available. Now you can get the most out of geolocation thanks to fewer limitations and increased functionality, including improvements in Visual Workflow, workflow updates and approvals, Apex, search tools, and more.

Spring ’15 includes the following changes to geolocation field limitations.

  • Geolocation fields are available in Visual Workflow and in formula-based criteria in workflow rules and approval processes, but cannot be used in filter-based criteria in workflow rules and approval processes.
  • Geolocation fields can be searched in SOQL and SOSL.
  • DISTANCE formulas are supported in:
    • Entry criteria for workflow rules and approval processes
    • Field update actions in workflow rules and approval processes
    • Custom validation rules
  • The only formula functions that you can use with compound fields are ISBLANK, ISCHANGED, and ISNULL. You can’t use BLANKVALUE, CASE, NULLVALUE, PRIORVALUE, or the equality and comparison operators with compound fields. The equality and comparison operators include = and == (equal), <> and != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal), && (AND), and || (OR).
  • Geolocation fields are now queryable in Apex. However, their locations are editable in Apex only as components of the compound field. Read and set geolocation field components by appending “__latitude__s” or “__longitude__s” to the field name, instead of the usual “__c.” For example:
    Double theLatitude = myObject__c.aLocation__latitude__s; 
    myObject__c.aLocation__longitude__s = theLongitude;
    

Use Visualforce Map Components to Show Location Data More Clearly

There are two new fantastic Visualforce tags, apex:map and apex:mapMarker, that are included as part of Spring ’15.

Visualforce mapping components make it simple to create maps that use third-party mapping services. Visualforce maps are interactive, JavaScript-based maps complete with zooming, scrolling, and markers based on your Salesforce or other data. Create stand-alone map pages, maps that you can insert into page layouts, and even mobile maps for Salesforce1.

Create Visualforce maps with a set of related mapping components. defines a map canvas, including map size, type, center point, and initial zoom level. child components define markers to place on the map, by address or geolocation (latitude and longitude).

Maps that you define generate JavaScript code to render onto the page. This JavaScript connects to a mapping service and builds the map by fetching map tiles, placing markers, and even geocoding addresses if you don’t have a latitude and longitude. After the map renders, your users can interact with the map by panning and zooming, just like they’re used to with other popular map sites. The effect is if you wrote your own custom JavaScript to interact with a third-party mapping service, but without needing to actually write that JavaScript. You define the map in Visualforce and get the mapping JavaScript for free.

An example of both tags in action:

<apex:page standardController="Account">
	<!-- This page must be accessed with an Account Id in the URL. For example: https://<salesforceInstance>/apex/NearbyContacts?id=001D000000JRBet -->
	<apex:pageBlock>
		<apex:pageBlockSection title="Contacts For {!Account.Name}">
			<apex:dataList value="{!Account.Contacts}" var="contact">
				<apex:outputText value="{!contact.Name}"/>
			</apex:dataList>
			<apex:map width="600px" height="400px" mapType="roadmap" center="{!Account.BillingStreet},{!Account.BillingCity},{!Account.BillingState}">
				<apex:repeat value="{!Account.Contacts}" var="contact">
					<apex:mapMarker title="{!contact.Name}" position="{!contact.MailingStreet},{!contact.MailingCity},{!contact.MailingState}"/>
				</apex:repeat>
			</apex:map>
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:page>

Result:

My Observations

Salesforce has done a fantastic job with this release of visualizing location data and making it more end user friendly. As the world becomes more and more mobile, this type of information will be very useful to have at your fingertips.

Enjoy and feel free to test it out on your own Spring ’15 Pre-Release Org!

One Response to “New Spring ’15 Features: Mapping”

  1. Greg
    June 19, 2015 at 4:24 am #

    Hello,
    Thanks for your sharing!
    I’m trying to find a solution on our saleforce application (we work on in order to display all of our contact on one map.
    When i try to copy and adapt your code in a Visualforce new page, it doesn’t run. And he says me ‘ No-know Composant apex:map’ whereas we have the last version…
    Do you know what’s happen?
    Thanks for your help, and all of your work on your blog.

Leave a Comment