Site icon UnofficialSF

From John Meyer: Flows on Salesforce Mobile that Use Your Phone’s Location Sensors

Note: The opinions here are those of the author and not those of Salesforce

In Salesforce’s Global Public Sector, we often delight Government customers who up until now have only dreamed of adding mobile capabilities to their operations. A great use case recently came from the U.S. National Weather Service. NWS relies on tens of thousands of volunteer weather spotters across the country who phone in weather conditions to various local branch offices across the nation. We showed them how we could automate the collection of the spotter reports with Flow and a couple of custom Lightning Web Components that retrieve and work with geolocation values returned by mobile devices.

Here are some images of the component in a flow embedded in a Salesforce Experience site on my mobile phone:

First, the mobile device asks for permission to use the spotter’s current location. Once granted, the component silently grabs the geolocation information from her phone while the spotter fills in the rest of the form in the flow. Finally, the confirmation page displays the information from the Flow-created spotter report record, showing the geolocation information pulled from the phone.

Following the demo, I bundled up the LWC and made it available on Salesforce’s open source component GitHub site


The component, its custom property editor, and a sample flow can be obtained by installing the unlocked package and installing for all users:

Once everything is installed in the org, you can add the geolocation component to your flow simply by dragging it onto the flow builder canvas from the “Custom” section of flow components. Note that by default the component does not display anything; it silently obtains the geolocation when the screen containing the component is shown in the flow. In the component’s configuration section, you can instead choose to display a map in the component showing your current location and an initial zoom level for that map. Also, by default, the component quietly fails if the component cannot determine the geolocation (if, for example, you choose not grant access to your geolocation or if the device does not support it). You can enable error messages for debugging purposes if you wish.

The component will return values for latitude and longitude (as decimal degrees), altitude (in meters relative to sea level), speed (in meters/sec), and heading (in degrees, with 0° representing true north).

Note: The speed and heading are only filled in when you are moving. If you wish to show the geolocation values in your flow, you can place the speed and heading values in a Display Text component with a visibility rule that tests to see if the speed value returned by the component is null.

The package contains an example flow that you can clone and use as a template for your own use cases.

I have tested this component on my iPhone and my Mac laptop, but since I am using standard web APIs, it should work on any other device that supports geolocation as well. I would be very interested to hear about your use cases below.

Bonus Component

The coordinates returned by this component make a fantastic way to keep track of records using Salesforce Maps. I also wrote a quick-and-dirty LWC to display a map of nearby records that you can place in a Salesforce record page for objects containing one or more geolocation fields. For my NWS demo, I showed nearby weather spotter reports:

To find out more about this component or to install it in your own org, please see the instructions on this GitHub page.

Skip to toolbar