> 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/projects/use-cases/reporting/library-returns-by-format.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Compare Library Returns by Format on a Salesforce Lightning Page

Build an Avonni stacked chart that adds up print, audio, and video returns by branch from Salesforce records.

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2FH4nLJVPeUfI37YCIMo1a%2Fproject-wave2-returns-hero.png?alt=media" alt="The Avonni stacked column chart in Salesforce compares print, audio, and video returns for Cedar Library and Riverside Library."><figcaption><p>Each column represents one branch, with a segment for each format.</p></figcaption></figure>

## Build the project

Choose how you want to build.

**Build with AI**. Give your AI assistant a ready-to-use prompt.

**Build it**. Follow the steps yourself.

{% tabs %}
{% tab title="Build with AI" icon="wand-magic-sparkles" slug="library-returns-by-format-build-with-ai" %}
{% stepper %}
{% step %}

### Set up your assistant and sandbox

Follow [Build with AI](https://docs.avonnicomponents.com/build-with-ai) to install the Avonni Skills and connect MCP. Use avonni-dynamic-components for this project.
{% endstep %}

{% step %}

### Copy the prompt and review the plan

{% code overflow="wrap" collapsedlinecount="10" %}

```
Build Library Returns by Format for a Salesforce Lightning page. Build an Avonni stacked chart that adds up print, audio, and video returns by branch from Salesforce records. Use the avonni-dynamic-components skill. Verify component APIs against Avonni MCP and inspect the installed package, the sandbox, and applicable permissions. Show your plan before making changes. Use only synthetic data in the sandbox.

Create a return-batch object

In a sandbox with Avonni Dynamic Components, use Setup > Object Manager to create Library Return Demo (Library_Return_Demo__c). Use a Text record name. Add Branch__c and Format__c as Text and Return_Count__c as Number with no decimal places.

Give the test user read access to the object, fields, and seven batch rows. Enter these counts as separate records. Cedar has two print batches so you can verify the chart sums records.

Cedar Library     Print 34   Audio 21  Video 10
Riverside Library Print 23   Audio 15  Video 12
Cedar Library     Print 6    (second batch)

Add the query and chart

In the Avonni Dynamic Components app, create Library Returns by Format. In Resources, create query LibraryReturnRows on Library_Return_Demo__c and limit it to 30 rows for the fixture. Add an Avonni Chart and select Stacked Column. Select the query as its data source.

Map each encoding and sum the counts

Under Data Mappings, choose Branch__c as the category for the columns, Format__c as the segment grouping and Return_Count__c as the measure. Set the aggregation to Sum. Turn on the legend and value labels. Label the axes Branch and Returned items.

Use the number format preset. The two Cedar Print rows, 34 and 6, should produce one Print segment of 40.

Add it to a test App Page and read the totals

Save and activate the Dynamic Component. Open Setup > Lightning App Builder and add AX - Dynamic Component to a sandbox App Page. Select Library Returns by Format, save, activate, and open the actual page.

Confirm Cedar totals 71 and Riverside totals 50. Check that the legend identifies the three formats within each branch. Keep the query cap above the number of batches in your own bounded time window so the chart includes every intended row.

Use the same scope and output as the manual guide. Show which steps need Builder, deployment or site access. Review all proposed metadata before any activation or publishing and activate only in the approved sandbox.

Check the result with these scenarios:

- Cedar’s Print segment is 40, with Audio 21 and Video 10 for a total of 71.

- Riverside shows Print 23, Audio 15 and Video 12 for a total of 50.

Report what you actually tested and which roles ran the checks.
```

{% endcode %}
{% endstep %}

{% step %}

### Test the result in Salesforce

Review the proposed changes before running them in the sandbox. Use the same sample values and verification checkpoints under Try it.
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Build it" icon="screwdriver-wrench" slug="library-returns-by-format-build-it" %}
{% stepper %}
{% step %}

### Create a return-batch object

In a sandbox with Avonni Dynamic Components, use **Setup > Object Manager** to create **Library Return Demo** (`Library_Return_Demo__c`). Use a Text record name. Add `Branch__c` and `Format__c` as Text and `Return_Count__c` as Number with no decimal places.

Give the test user read access to the object, fields, and seven batch rows. Enter these counts as separate records. Cedar has two print batches so you can verify the chart sums records.

{% code overflow="wrap" collapsedlinecount="10" %}

```
Cedar Library     Print 34   Audio 21  Video 10
Riverside Library Print 23   Audio 15  Video 12
Cedar Library     Print 6    (second batch)
```

{% endcode %}
{% endstep %}

{% step %}

### Add the query and chart

Create **Library Returns by Format** in the Dynamic Component Builder. Under Resources, add `LibraryReturnRows` on `Library_Return_Demo__c`. For the seven sample batches, leave the filter blank, sort by `Name ASC`, and set the limit to 30.

Drag **Chart** onto the canvas, set its API name to `ReturnsChart`, select **Stacked Column** and set **Data Source** to **Query** > **Library Return Rows**.

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2F5YxCV74CU9WS5PPKWLJu%2Fproject-wave2-returns-editor.png?alt=media" alt="The Chart configuration in Salesforce Avonni Dynamic Component Builder."><figcaption><p>Start with the real Salesforce query before setting the chart’s groupings.</p></figcaption></figure>
{% endstep %}

{% step %}

### Map each encoding and sum the counts

Open **Data Mappings**. Add the measure to **Bar Length** and set its aggregation to **Sum**. Add **Bars** and **Bar Segments** as separate encodings.

| Setting                   | Value                                                  |
| ------------------------- | ------------------------------------------------------ |
| Bar Length                | Return Count (`Return_Count__c`) · Sum · number format |
| Bars                      | Branch (`Branch__c`)                                   |
| Bar Segments              | Format (`Format__c`)                                   |
| Show Legend / Show Values | On / On                                                |
| X-axis / Y-axis title     | Branch / Returned items                                |

The two Cedar Print batches, 34 and 6, should now share one Print segment of 40.
{% endstep %}

{% step %}

### Add it to a test App Page and read the totals

Save and activate the Dynamic Component. Open **Setup > Lightning App Builder** and add **AX - Dynamic Component** to a sandbox App Page. Select **Library Returns by Format**, save, activate, and open the actual page.

Confirm Cedar totals 71 and Riverside totals 50. Check that the legend identifies the three formats within each branch. Keep the query cap above the number of batches in your own bounded time window so the chart includes every intended row.

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2FH4nLJVPeUfI37YCIMo1a%2Fproject-wave2-returns-hero.png?alt=media" alt="Salesforce shows the two stacked branch columns and the format legend."><figcaption><p>Check Cedar’s Print segment of 40 to verify the Sum aggregation.</p></figcaption></figure>

<figure><img src="https://3857391697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdHOej9Pd5IxJNGEJMZKW%2Fuploads%2FilNmisrtjxpuzUDatqAw%2Fprojects-build-review-returns-measure.png?alt=media" alt="The stacked Avonni chart in Salesforce shows the value 40 on the Cedar Library Print segment."><figcaption><p>Use the Cedar Print value of 40 to confirm that the segment sums both batch records.</p></figcaption></figure>
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## Try it

Cedar’s Print segment is 40, with Audio 21 and Video 10 for a total of 71.

Riverside shows Print 23, Audio 15 and Video 12 for a total of 50.

Avonni groups and sums the records returned by the query. Salesforce supplies the underlying return batches and record visibility.

## Component references

[Chart](https://docs.avonnicomponents.com/dynamic-components/components/chart.md)

## Review status

Verified in the academy-experience Lightning runtime with Avonni Experience Components 1.29.0.3. The administrator saw both branch stacks, the format legend, and Cedar’s Print sum of 40. The chart used seven fictional Salesforce rows. Captured in the addressable Lightning test wrapper.


---

# 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/projects/use-cases/reporting/library-returns-by-format.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.
