> 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/flow/tutorials/components/timeline/show-a-record-history-with-a-query.md).

# Show a record history with a query

Let the Avonni Timeline query an account's Cases itself, with no Get Records, so support sees the latest case activity as soon as the screen opens.

Before a renewal call with Harbor Point Logistics, a support lead wants the account's Cases on one screen, the most recently updated on top. With the **Query** data source, the **Avonni Timeline** fetches the records itself when the screen opens, filtered on the current account. The flow needs no **Get Records** element.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FuXRQOeW7sOkXftWnJxZl%2Ftimeline-show-a-record-history-with-a-query-result.png?alt=media" alt="Avonni Timeline listing the account&#x27;s Cases by last update, the first opened on its Case Number, Status and Priority" width="440"><figcaption><p>The account's Cases, loaded by the Timeline's own query.</p></figcaption></figure>

## Before you start

* A screen flow with a text input variable `recordId`, launched from the Account record page with the record ID passed in. [How to pass your current RecordID in your screen flow](https://docs.avonnicomponents.com/flow/tutorials/tips-and-tricks/how-to-pass-your-current-recordid-in-your-screen-flow.md) shows how.
* A screen with the **Avonni Timeline** on it. [Display Tasks](https://docs.avonnicomponents.com/flow/tutorials/components/timeline/display-tasks.md) shows how to add it.

## When to use Query instead of Variable

|                                 | **Variable**                                                                                                                                                                                                  | **Query**                                       |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| Records come from               | A collection the flow built, usually a Get Records                                                                                                                                                            | The Timeline queries them when the screen opens |
| Extra flow elements             | One Get Records per object                                                                                                                                                                                    | None                                            |
| Several objects in one timeline | Yes, through the [SObject Collection to Activity Timeline Items](https://docs.avonnicomponents.com/flow/actions/data-manipulation-and-transformation/sobject-collection-to-activity-timeline-items.md) action | No, one object per Timeline                     |
| Filters, Search Fields          | Yes                                                                                                                                                                                                           | Yes                                             |

## Steps

{% stepper %}
{% step %}

### Set the data source to Query

1. Select the **Avonni Timeline** on the screen and click **Open Component Builder**.
2. In the **Properties** tab, open the **Data Source** section and click **Query**.
3. In **Object API Name**, pick **Case**.
   {% endstep %}

{% step %}

### Filter on the current account

Under **Filters**, add a condition on the Case's account lookup, **Account ID** (`AccountId`), **Equals** the `recordId` resource of the flow.

Without this filter, the Timeline lists every Case the running user can see.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FClSuj09fzsHZyJNS3uHS%2Ftimeline-show-a-record-history-with-a-query-filters.png?alt=media" alt="Query data source on Case with the filter Account ID Equals recordId, ordered by Last Modified Date descending, limited to 20 records" width="320"><figcaption><p>The query reads the flow's recordId, so no Get Records is needed.</p></figcaption></figure>
{% endstep %}

{% step %}

### Keep the latest records

1. Under **Order By**, sort on **Last Modified Date**, descending.
2. Set **Maximum Number of Records** to `20`.

The order decides which 20 Cases are loaded. The Timeline then sorts them by their date on its own.
{% endstep %}

{% step %}

### Map what each item shows

In **Data Mappings**:

* **Title**: `Subject`.
* **Description**: `Description`.
* **Start Date**: `LastModifiedDate`, so each Case sits at its last update.
* **Avatar** > **Icon Name**: switch to Manual and pick `standard:case`.
* **Fields**: add **Case Number**, **Status** and **Priority**.
* **Key Field**: keep `Id`.

{% hint style="info" %}
The builder has a ready-made version of this setup. In the Component Builder's left panel, open **Templates**, then **Standard**, and pick **Last Modified Cases**: it sets a Query on Case that maps the subject, description and last modified date and shows **Type** and **Case Number**, opens the Case on **Item Click** and adds an **Edit** action. It has no account filter: add the one from step 2.
{% endhint %}
{% endstep %}

{% step %}

### Save and test

Click **Done**, save the flow and open it from an Account record page. The Timeline lists that account's Cases, the most recently updated first, each with its subject, case number, status and priority. Update a Case, reopen the screen: it moves to the top.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>The timeline lists Cases from other accounts</summary>

The **Filters** condition is missing, or it compares the Case's own ID with `recordId`. Filter on the account lookup (`AccountId`) instead.

</details>

<details>

<summary>The timeline is empty at runtime but `recordId` is set</summary>

The query runs as the running user: it returns only the Cases that user can read. Check the user's access to the account's Cases, and that a Case exists for that account.

</details>

<details>

<summary>A new Case does not appear until the screen is reopened</summary>

The query runs when the screen opens. To reload it on the same screen, add a **Refresh Query** interaction to **Header Action Click** or **Item Click** in the **Interactions** tab.

</details>

## Related tutorials

* [Display Tasks](https://docs.avonnicomponents.com/flow/tutorials/components/timeline/display-tasks.md): the same timeline fed by a Get Records collection.
* [Assigning multiple source collections to the Timeline](https://docs.avonnicomponents.com/flow/tutorials/components/timeline/assigning-multiple-source-collection-to-the-timeline.md): Cases, Tasks and Events in one timeline.
* [Act on a timeline item](https://docs.avonnicomponents.com/flow/tutorials/components/timeline/act-on-a-timeline-item.md): reload the query after a user edits an item.
* [Filter a Data Table or Map by the current record in a screen flow](https://docs.avonnicomponents.com/flow/tutorials/tips-and-tricks/filter-a-data-table-or-map-by-the-current-record.md): the same `recordId` filter on other components.


---

# 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/flow/tutorials/components/timeline/show-a-record-history-with-a-query.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.
