> 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/pdf-viewer/pick-a-pdf-from-a-list.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Pick a PDF from a List and Read It

List every PDF attached to an Opportunity and open the one a user clicks in a viewer beside the list, without leaving the record page.

An Opportunity collects a draft contract, the signed one, an invoice and a pricing proposal. The account executive wants to flip between them while on the phone with the customer. A [List](https://docs.avonnicomponents.com/dynamic-components/components/list.md) shows the record's PDFs on the left; a click opens that file in the [PDF Viewer](https://docs.avonnicomponents.com/dynamic-components/components/pdf-viewer.md) on the right.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2F93Ddf1rTPuq6sv2DXqYr%2Fpdf-viewer-pick-a-pdf-result.png?alt=media" alt="Files list with four PDFs, Invoice INV-10482 highlighted, and the invoice open in the PDF viewer beside it"><figcaption><p>Click a file in the list and it opens on the right; the highlight shows which one is open.</p></figcaption></figure>

## Before you start

* An Opportunity with several PDFs uploaded to it. This page uses Northwind Fleet Renewal and its four files: Service Contract 2027 (signed), Service Contract 2027 (draft), Invoice INV-10482 and Fleet Pricing Proposal.
* PDFs set to open in the browser: see the warning in [PDF Viewer](https://docs.avonnicomponents.com/dynamic-components/components/pdf-viewer.md).
* A Dynamic Component with the **Target Page Object** set to `Opportunity`. See [Target Page Object](https://docs.avonnicomponents.com/dynamic-components/core-concepts/target-page-object.md).

## Build it

Choose how you want to build:

✨ **Build with AI**: give your AI assistant a ready-to-use prompt.

🛠️ **Build with clicks**: follow the steps in the builder yourself.

{% tabs %}
{% tab title="Build with AI" icon="wand-magic-sparkles" slug="pick-a-pdf-build-with-ai" %}
The `avonni-dynamic-components` skill drafts the two-column layout, the List with its query and the bound PDF Viewer; Salesforce must already hold the files on the Opportunity.

{% stepper %}
{% step %}

### Set up the Avonni Skills and MCP server

Follow [Setup](https://docs.avonnicomponents.com/dynamic-components/build-with-ai/setup.md) to install the Avonni Skills, connect your AI assistant to the Avonni MCP server, and sign in to your sandbox through Salesforce CLI.

Upload two or three PDFs to a test Opportunity first, so the plan can be checked against real files.
{% endstep %}

{% step %}

### Copy the prompt and review the plan

Paste the prompt into your configured assistant. Check the target org and the field mappings in its plan before you approve it.

{% prompt description="Prompt for this tutorial" icon="wand-magic-sparkles" openInAIProviders="false" defaultExpanded="partial" %}
{% code overflow="wrap" collapsedlinecount="10" %}

```
Use the avonni-dynamic-components skill. Verify the dcLayout, dcList and dcPdfViewer components and the List's clickedItemSObject output against the Avonni MCP server (dynamic toolset) before you use any name.

Inspect my sandbox: confirm ContentVersion records exist with FirstPublishLocationId set to an Opportunity, FileExtension pdf and IsLatest true. Confirm the fields Title, ContentDocumentId and CreatedDate.

Create a Dynamic Component with Target Page Object Opportunity. Add a Columns component with two columns. In the left column, add a List with API name PdfFiles and title "Files", using a query on ContentVersion filtered on FirstPublishLocationId equal to the current record Id, FileExtension equal to pdf and IsLatest true, sorted by CreatedDate descending; map the item Label to Title. Turn on Items Clickable and Highlight On Click. In the right column, add a PDF Viewer with Source {!PdfFiles.clickedItemSObject.ContentDocumentId}, Show Placeholder on, Placeholder Message "Pick a file to read it here.", Placeholder Illustration Preview, and a Height of 600px in its Size style.

Show me the plan and the field bindings before writing files. Then draft the local metadata, list what is left to set up by hand, and stop before deployment or activation.
```

{% endcode %}
{% endprompt %}
{% endstep %}

{% step %}

### Deploy to the sandbox and check the result

Review what the assistant generated and what it left for you to configure. Deploy the approved files to your sandbox only, finish any remaining setting with the **Build with clicks** tab, then check that clicking Invoice INV-10482 in the list opens the invoice in the viewer.
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Build with clicks" icon="screwdriver-wrench" slug="pick-a-pdf-build-with-clicks" %}
{% stepper %}
{% step %}

### Lay out two columns

Drag a **Columns** component onto the canvas, with two columns: a narrow one for the list, a wide one for the PDF. See [Columns](https://docs.avonnicomponents.com/dynamic-components/components/columns.md) for the column sizes.
{% endstep %}

{% step %}

### List the record's PDFs

1. Drag a **List** into the left column, set its API name to `PdfFiles` and its **Title** to `Files`.
2. Set its data source to **Query**, click **Edit the query** and set **Object API Name** to **Content Version**.
3. Add three filters, all met: **First Publish Location ID** equals the current record's Id, **File Extension** equals `pdf`, **Is Latest** equals true.
4. Sort by **Created Date**, descending, so the newest file comes first.
5. Map the item **Label** to **Title**.

*Why Is Latest:* each new version of a file is a new Content Version. Without this filter, a file uploaded twice appears twice.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FTZlIEuRYm1QQXode8XPC%2Fpdf-viewer-pick-a-pdf-query.png?alt=media" alt="List query editor on Content Version with three filters and Created Date descending" width="480"><figcaption><p>Three filters, all met, and the newest file first.</p></figcaption></figure>
{% endstep %}

{% step %}

### Make the files clickable

Select `PdfFiles` and, in the Properties tab:

1. Turn on **Items Clickable**. Each click stores the clicked file in the List's **Clicked Item sObject** output.
2. Turn on **Highlight On Click**, so the user sees which file is open.

No interaction is needed: the output updates on every click.
{% endstep %}

{% step %}

### Bind the viewer to the clicked file

1. Drag a **PDF Viewer** into the right column.
2. Set **Source** to `{!PdfFiles.clickedItemSObject.ContentDocumentId}`. From the resource list: **Pdf Files**, then **Clicked Item sObject**, then **Content Document ID**. Source then shows a **Content Document ID** pill.
3. In the **Placeholder** section, turn on **Show Placeholder**, set **Placeholder Message** to `Pick a file to read it here.` and **Placeholder Illustration** to **Preview**. Before the first click, **Source** is empty and the placeholder fills the column.
4. In the **Style** tab, under **Size**, set **Height** to `600` (unit **px**).

Bind **Content Document ID**, not the record **Id**: the record Id of a Content Version starts with `068`, and the viewer only recognizes ContentDocumentIds (`069`).

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FP1fD2pTi4w6VXnWPy0EE%2Fpdf-viewer-pick-a-pdf-source-binding.png?alt=media" alt="Edit Pdf Viewer panel with Source bound to Content Document ID and the Preview placeholder" width="480"><figcaption><p>Source reads the clicked file's Content Document ID; the placeholder covers the time before the first click.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test

1. Save the component, add it to the Opportunity record page in Lightning App Builder, and open Northwind Fleet Renewal.
2. The list shows the four PDFs, newest first. The viewer shows "Pick a file to read it here."
3. Click Invoice INV-10482. It turns highlighted and the invoice opens on the right.
4. Click Fleet Pricing Proposal. The highlight moves and the viewer switches file.
   {% endstep %}
   {% endstepper %}
   {% endtab %}
   {% endtabs %}

## Troubleshooting

<details>

<summary>The list is empty</summary>

The query only finds files uploaded on this Opportunity (**First Publish Location ID**), with the extension `pdf`. A file shared from another record is linked through **Content Document Link**, not through this field. Also check that the user viewing the page can see the files: the query runs with their permissions.

</details>

<details>

<summary>A click highlights the file but the viewer stays blank</summary>

Check that **Source** points at **Content Document ID** and not at **Id**. For the other causes, see the blank viewer checklist in [Show a PDF from a URL on a Record](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-a-pdf-from-a-url.md).

</details>

<details>

<summary>Nothing happens on click</summary>

Turn on **Items Clickable** on the List.

</details>

## Related tutorials

* [Show the Latest Contract on an Opportunity](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-the-latest-contract-on-an-opportunity.md): open one file automatically instead of letting the user pick.
* [Show a Placeholder When No PDF Is Attached](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/pdf-viewer/show-a-placeholder-when-no-pdf.md): more on the placeholder used before the first click.
* [Click a card to see its details](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/repeater/click-for-details.md): the same "click, then read beside it" pattern with a Repeater.


---

# 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/pdf-viewer/pick-a-pdf-from-a-list.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.
