Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Draw a Territory and Save It to the Record

Let a sales manager draw a territory on an Avonni Map in a screen flow, save it as a file on the account, and reopen it later to edit.

A sales manager gives a distributor the exclusive zone south of Market Street. From the distributor's account, she opens a flow, traces the zone around the accounts it should cover, and clicks Save territory. The shape is saved as a file on the account, and the flow shows it again the next time she opens it.

A San Francisco account map with a blue polygon drawn over SoMa around six account pins, a drawing toolbar with polygon, edit and delete tools at the top right, and a Save territory button under the map.
A territory traced over SoMa, saved to the account with Save territory.

Before you start

  • The map uses Type Leaflet: drawing does not exist on Google Maps. See Map.

  • On Account, a text field to remember the saved file, for example Territory File Id (Territory_File_Id__c, Text, 18 characters).

  • The users who draw can create Files on the account.

Steps

1

Get the account in the flow

  1. Create a screen flow with a Text variable recordId, Available for input.

  2. Add a Get Records element named Get_Account: Account where Account ID equals {!recordId}, first record only.

  3. Create a Text formula TerritoryTitle: "Territory - " & {!Get_Account.Name}.

2

Add the map

Add a Screen element after Get_Account and drag an Avonni Map onto it. Name it map.

  1. In the Properties tab, set Type to Leaflet.

  2. Set Data Source to Query on Account, for example where Billing City equals San Francisco, so the manager sees the accounts she is enclosing.

  3. In Data Mappings, map Title to Account Name, and under Location map Latitude to Billing Latitude and Longitude to Billing Longitude.

3

Turn on drawing

Open the Draw group:

  1. Turn on Enable Draw. A drawing toolbar appears on the map.

  2. In Toolbar, keep Polygon, Edit and Delete, and remove the others. A territory is an outline, so the manager needs no lines or markers.

  3. Set Toolbar Position to Top Right.

4

Save the drawing as a file on the account

Still in Draw, turn on Save as Content Document. Its settings appear below it.

Setting
Value
Why

Content Document Id

{!Get_Account.Territory_File_Id__c}

Empty the first time, so a new file is created. Filled later, so the saved shape opens again and Save updates that same file

Content Document Title

{!TerritoryTitle}

The file reads "Territory - " and the account name

Content Document Linked Entity Id

{!recordId}

The file is attached to the account

Save Button Label

Save territory

The button under the map

The Draw group of the Map's Properties tab: drawing enabled with the polygon, edit and delete tools, Save as Content Document on, the file linked to the record Id and the save button labeled Save territory.
Draw settings that save the territory as a file on the account.
5

Store the file Id on the account

After the screen, the Map's Content Document Id output holds the saved file.

  1. Add a Decision after the screen: continue only when {!map.contentDocumentId} Is Null is False. A manager who closes the screen without saving changes nothing.

  2. On that path, add an Update Records element: Account where Account ID equals {!recordId}, set Territory File Id to {!map.contentDocumentId}.

6

Add the flow to the account page

Activate the flow. In Lightning App Builder, add the Flow component to the Account record page, pick the flow, and check Pass record ID into this variable for recordId.

7

Save and test

  1. Open an account, pick the polygon tool and click around a few accounts on the map. Click the first point again to close the shape.

  2. Click Save territory. A message confirms "Your content document has been created." The file appears in the account's Files.

  3. Click Next. The account's Territory File Id is filled.

  4. Open the flow again from the same account. The territory is back on the map. Move a corner with Edit and click Save territory: the message now reads "Your content document has been updated."

The file is saved only when the manager clicks the save button. With Auto Save Content Document on, the button disappears and each change is written to the file.

Keep the shape in a field instead of a file

Every shape drawn is also available, as GeoJSON text, in the Map's Draw GeoJSON Value output, file or no file.

  1. Leave Save as Content Document off and add a Long Text Area field to Account, for example Territory GeoJSON.

  2. After the screen, an Update Records element sets Territory GeoJSON to {!map.drawGeoJsonValue}.

  3. To open the shape again, set the Draw GeoJSON Value setting in the Draw group to {!Get_Account.Territory_GeoJSON__c}. It shows only while Save as Content Document is off.

The same output can feed the next screen, for example a second map whose GeoJSON Value shows the territory read-only for a final check.

Troubleshooting

"Error creating your content document" when saving

Content Document Linked Entity Id is empty or is not a record Id at run time, or the user cannot create Files on that record. Check that the flow receives recordId from the page.

"Error updating your content document"

The file in Territory File Id was deleted, or the user cannot edit it. Clear the field on the account so the next save creates a new file.

The drawing toolbar is missing

Check that Type is Leaflet and Enable Draw is on.

Was this helpful?