Skip to main content

Calculate distance and travel time in a flow

The flair Distance Calculation action returns the driving or direct distance in kilometres and the travel time in minutes between two locations. You can add it to your own Salesforce Flows to store or act on that distance — for example, to populate a field or branch on how far apart two addresses are.

Who can use this?

Salesforce Admins building flows in Salesforce Flow Builder. The flair managed package must be installed.

Before you begin​

  • The flair managed package is installed in your org.
  • You have permission to create and activate flows in Salesforce Setup.

Add the Distance Calculation action to a flow​

Add the action wherever your flow needs a distance — for example, in a record-triggered flow after the relevant addresses are set.

  1. In Setup, open Flows and open your flow, or click New Flow to create one.
  2. On the flow canvas, click the + where you want the calculation to run, then select Action.
  3. In the action search, enter Distance Calculation and select it.
  4. Enter a Label for the action. The API Name fills in from the label.
  5. Set the input values for the action (see Set the input values).
  6. Close the action panel. The action stays on the canvas; click Save to save the flow.

The Distance Calculation action in Flow Builder with its label and input values

Set the input values​

Provide the two locations as either addresses or coordinates, and choose the calculation type. Type is required.

InputWhat it does
TypeThe calculation method. Enter DRIVING for the driving distance along roads, or DIRECT for the straight-line distance. Required.
Address FromThe start location as an address.
Address ToThe end location as an address.
StopsOptional addresses between Address From and Address To, one per line, in travel order.
Latitude From, Longitude FromThe start location as coordinates.
Latitude To, Longitude ToThe end location as coordinates.
Request IDOptional identifier for the request. If you leave it empty, flair generates one.

Provide each location one way or the other: set Address From and Address To, or set the latitude and longitude pair for each end. To pull a value from the triggering record, select the field from the record variable — for example, $Record and then the address field.

Calculate a route with stops​

To calculate a route such as A → B → C, set Address From, Address To, and Stops. flair calculates one leg between each pair of consecutive addresses and returns the sum of the distances and travel times. With stops, the action uses the addresses only, not the latitude and longitude inputs.

  • A route can have at most 8 stops of up to 255 characters each. If a route has more stops or a longer stop, the action returns an error and no distance.
  • If one leg can't be calculated, the whole route fails and returns an error, so a shorter distance is never returned.

flair's own mileage calculation uses this input: it passes the Stops field of an Expense Item and recalculates the distance when the stops change.

Use the results​

The action returns these outputs, which you can store in variables or reference in later flow elements:

OutputWhat it contains
distanceInKmThe distance between the two locations, in kilometres.
durationInMinutesThe travel time between the two locations, in minutes.
errorA message describing why the calculation failed, if it did.
  1. After the action, add the flow element that uses the result — for example, an Update Records or Assignment element.
  2. Reference the action's distanceInKm or durationInMinutes output in that element.
  3. Optional: add a Decision element that checks whether error is empty before using the result, so the flow handles failed calculations.
  4. Click Save, then click Activate to run the flow.