> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/draw-and-save-a-sales-territory.md).

# Draw and Save a Sales Territory

Draw a coverage boundary around customer accounts on Avonni Map and save the polygon as a GeoJSON file linked to a Salesforce account.

A sales manager wants to keep a record of the area served by the Northwind Traders account. Use Avonni Map to draw a boundary around two Chicago customer sites and save the outline as a Salesforce file on that account.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FheHMIweGtuA2EL7iAlUb%2Fsales-territory-result.jpg?alt=media" alt="A polygon outlines two northern Chicago account markers, with three markers outside it and the Save territory button below."><figcaption><p>The territory encloses the two north-side customer sites. Map data © OpenStreetMap contributors.</p></figcaption></figure>

## Before you start

* Use a Dynamic Component that you can save and test on a Lightning page. This tutorial uses **Leaflet**, which provides the drawing toolbar.
* Prepare the five test accounts listed in [Plan a Multi-Stop Visit Route](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/plan-a-multi-stop-visit-route.md), including their billing coordinates. You only need the account data for this tutorial.
* Choose the test account that should hold the file. This example uses **Northwind Traders**. Keep its Salesforce record ID handy and confirm that the test user can create and link files to the account.

## Steps

{% stepper %}
{% step %}

### Show the accounts inside and outside the territory

1. Add **Map** in Component Builder. In **Properties** > **Content**, set **Type** to **Leaflet** and **Zoom Level** to `11`.
2. Set **Data Source** to **Query** on **Account** and filter to the five Chicago test accounts. In **Data Mappings**, map **Title** to `Name`, **Value** to `Id`, and **Location** > **Latitude** and **Longitude** to `BillingLatitude` and `BillingLongitude`.
3. Set **Header** > **Title** to `Sales territories`. Under **Map Center Location**, enter latitude `41.89` and longitude `-87.66` to start over the Chicago sites.
   {% endstep %}

{% step %}

### Enable drawing and choose where to save

1. In **Draw**, turn on **Enable Draw**. In **Toolbar**, keep **Polygon**, **Edit**, and **Delete**. Set **Toolbar Position** to **Bottom Right**.
2. Turn on **Save as Content Document** and leave **Auto Save Content Document** off so the user chooses when to save.
3. Set **Content Document Title** to `North Chicago Sales Territory`. Set **Content Document Linked Entity Id** to the Northwind Traders Account ID.
4. Leave **Content Document Id** empty for the first save. Set **Save Button Label** to `Save territory`.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F6XM5C1I1lHn8eefl8m2n%2Fsales-territory-settings.jpg?alt=media" alt="Map Draw settings with Save as Content Document on, Auto Save Content Document off, an empty Content Document Id, and North Chicago Sales Territory as the file title." width="320"><figcaption><p>Enable file saving and leave Content Document Id empty to create a new file.</p></figcaption></figure>
{% endstep %}

{% step %}

### Draw the north-side boundary

Save and activate the Dynamic Component. Place it on a test Lightning page, then save, activate, and open that page. Select the polygon tool and click around Blue Finch Retail and Northwind Traders. Keep Atlas Logistics, Redwood Supply Co, and Juniper Health outside the boundary. Click the first vertex again to close the polygon.
{% endstep %}

{% step %}

### Save and test

1. Before saving, check that the outline encloses exactly two of the five account markers. Confirm that the test account does not already have a file called **North Chicago Sales Territory**.
2. Click **Save territory**. In Salesforce, open **Northwind Traders** and check that **Files** shows a new **North Chicago Sales Territory** file linked to that account.
3. Download the file and open the JSON. Look for a GeoJSON feature whose geometry type is `Polygon`. Compare its boundary with the territory drawn on the map. GeoJSON stores each position in longitude, latitude order.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

<details>

<summary>The drawing toolbar or save button is missing</summary>

Check **Content** > **Type** and confirm that **Enable Draw** and **Save as Content Document** are on. The manual save button appears when **Auto Save Content Document** is off.

</details>

<details>

<summary>The file does not appear on the account</summary>

Check that **Content Document Linked Entity Id** contains the intended Account record ID and that the test user can create files and link them to that account. Test the save from the Lightning page.

</details>

## Related tutorials

* [Map Accounts by Industry](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/map-accounts-by-industry.md) shows how to identify the types of accounts inside your boundary.
* [Plan a Multi-Stop Visit Route](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/plan-a-multi-stop-visit-route.md) shows how to plan a driving route through a set of customer sites.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/draw-and-save-a-sales-territory.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
