> 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/map-accounts-by-industry.md).

# Map Accounts by Industry

Map Salesforce Accounts in Leaflet and color each marker by industry, so your territory team can see where customers in each sector are located.

A territory manager needs to see where customers in different sectors are located around Chicago. Use Avonni Map to plot Salesforce Accounts as pins. A Salesforce formula supplies the color, and the marker popup shows the Account's industry.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fc3SEqyWuUnbvvhCsaTUF%2Fmap-accounts-by-industry-result.jpg?alt=media" alt="Five Chicago Account pins. Two are blue, two are orange, and one is gray."><figcaption><p>The formula field gives each pin its industry color. Map data © OpenStreetMap contributors.</p></figcaption></figure>

## Before you start

* Use a Salesforce test org with Avonni Dynamic Components and access to Component Builder. Viewers need read access to the Accounts and fields used here.
* Prepare five test Accounts with distinct billing coordinates. This example uses Atlas Logistics and Redwood Supply Co in Transportation, Blue Finch Retail and Northwind Traders in Retail, and Juniper Health with a blank Industry.
* For Leaflet's default map tiles, add `https://tile.openstreetmap.org` to **Trusted Sites** if it is missing. See the [Map reference](https://docs.avonnicomponents.com/dynamic-components/components/map.md) for the provider requirements.

Use the five Chicago accounts and coordinates in [Plan a Multi-Stop Visit Route](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/plan-a-multi-stop-visit-route.md). Create one additional test Account with no billing coordinates for the query check.

## Steps

{% stepper %}
{% step %}

### Create a formula field for the color

In Salesforce **Object Manager** for Account, create a **Formula** field named **Map Marker Color** (`Map_Marker_Color__c`) with the **Text** return type. Give test viewers read access to it. Use the stored values from your Industry picklist.

```
CASE(
    Industry,
    "Transportation", "#0070D2",
    "Retail", "#B95000",
    "#58656E"
)
```

Transportation returns blue, Retail returns orange, and other values or a blank Industry return gray.
{% endstep %}

{% step %}

### Query the test Accounts

1. Add **Map** to the Dynamic Component canvas. Select it and open **Properties**.
2. Under **Content**, set **Type** to **Leaflet** and **Zoom Level** to `11`.
3. Under **Data Source**, choose **Query**. Select **Create a Query** and choose **Account** as the object.
4. Filter the query to your six test Accounts, including the one with no coordinates. Require both **Billing Latitude** and **Billing Longitude**. For each field, use **not equal to** and select **Global Constants** > **Null** in the value picker. Combine the coordinate filters with the test-record filter using AND.
5. Save the query.
   {% endstep %}

{% step %}

### Map the fields and marker style

Open **Data Mappings** in the Map properties.

| Setting                      | Value                                        |
| ---------------------------- | -------------------------------------------- |
| **Title**                    | Account Name (`Name`)                        |
| **Value**                    | Account ID (`Id`)                            |
| **Location** > **Latitude**  | Billing Latitude (`BillingLatitude`)         |
| **Location** > **Longitude** | Billing Longitude (`BillingLongitude`)       |
| **Type**                     | **Pin**                                      |
| **Fill Color**               | **Map Marker Color** (`Map_Marker_Color__c`) |
| **Fields**                   | **Industry**                                 |

For **Fill Color**, select **Mapped** and choose your formula field so each Account supplies its own value. In **Map Center Location**, enter `41.8819` for **Latitude** and `-87.6335` for **Longitude** to start over Chicago. In **Header**, set **Title** to `Accounts by industry`.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FKbHwTRej2p0SuTjnXIYA%2Fmap-accounts-by-industry-mapping.jpg?alt=media" alt="The Map builder shows Type set to Pin and Fill Color mapped to the Account formula field." width="320"><figcaption><p>Use the Account formula field as the mapped fill color.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test

1. Save and activate the Dynamic Component. Place it on a test Lightning page and open the activated page.
2. From the Account records, check the expected colors against the formula. Confirm two blue, two orange and one gray pin. Open a marker from each group and check its title and Industry against Salesforce. Juniper Health should still have a marker when Industry is blank.
3. Change one test Account from Transportation to Retail, refresh the page, and check that its pin changes from blue to orange without moving. Restore the original Industry after the test.
4. Confirm the query’s coordinate filters keep the Account without coordinates off the map.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

* **Every pin has the same fill.** Check that **Fill Color** is mapped to the Account formula field, and compare the formula's text on two Accounts with different industries.
* **An Account is missing.** Open the Salesforce record and check both coordinates, the query filters and the viewer's field access. Leaflet needs a latitude and longitude for each marker.

## Related tutorials

* [Show Account Details on Marker Select](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/show-account-details-on-marker-select.md) adds a Salesforce record panel to the same map.
* [Center a Map on the Current Account](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/center-a-map-on-the-current-account.md) shows an individual Account location on its own record page.
* [Query](https://docs.avonnicomponents.com/dynamic-components/component-builder/data-sources/query.md) explains filters and viewer access.


---

# 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/map-accounts-by-industry.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.
