> 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/component-builder/data-sources/query.md). Agents can also search and read this documentation through its [MCP server](https://docs.avonnicomponents.com/~gitbook/mcp).

# Query

Let an Avonni Data Table read open opportunities itself, with filters, an order and a record limit, so it can show parent fields and reload on demand.

The account executives want the deal review screen to list every open opportunity with its account, sorted by close date, and to filter it by stage without leaving the screen. With the **Query** data source, the Avonni Data Table reads the opportunities itself when the screen opens. No Get Records element, and the Account Name column comes straight from the parent account.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2F2xbIDLnKcuWyBHVtP5rN%2Fflow-builder-query-result.png?alt=media" alt="Data Table of open opportunities sorted by close date, with the account name of each deal"><figcaption><p>Open opportunities read by the table itself, sorted by Close Date, with the parent account's name.</p></figcaption></figure>

You build the query with clicks: an object, filter conditions, an order and a maximum number of records. There is no SOQL text box. The query runs with the permissions of the user who runs the flow.

## Before you start

* A screen flow with an Avonni [Data Table](https://docs.avonnicomponents.com/flow/flow-components/data-table.md) on a screen. The same Query source exists on the List, Map, Kanban, Combobox and other components that display records.
* Read access to Opportunity and Account for the users who run the flow.
* Not sure Query is the right source? See [Understanding Data Sources](https://docs.avonnicomponents.com/flow/component-builder/data-sources/understanding-data-sources.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="query-build-with-ai" %}
The `avonni-flow-components` skill drafts the Data Table with its query and column mappings. Salesforce must already hold the screen flow.

{% stepper %}
{% step %}

### Set up the Avonni Skills and MCP server

Follow [Setup](https://docs.avonnicomponents.com/flow/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.

You need the "Review open deals" screen flow and a few open opportunities in the sandbox to check the result.
{% 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-flow-components skill. Verify the Avonni Data Table component and its Query data source against the Avonni MCP server before you configure anything.

Inspect my sandbox: confirm the Opportunity fields Name, StageName, Amount, CloseDate and IsClosed, the Account relationship and its Name field, and the screen flow "Review open deals". Tell me which screen you will add the table to.

Add an Avonni Data Table with the Query data source on Opportunity: one filter condition IsClosed equals false, Order By CloseDate ascending, Maximum Number of Records 200. Map five columns: Name, Account Name (Account.Name), Stage, Amount and Close Date. Leave System Mode off.

Show me the plan and the field bindings before you write any file. Then draft the local flow metadata, list what I still have to set up by hand, and stop before deploying or activating anything.
```

{% 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 run the flow in **Debug** and check that the table lists open opportunities only, earliest close date first, with the account of each deal.
{% endstep %}
{% endstepper %}
{% endtab %}

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

### Choose Query and the object

1. In Flow Builder, open the screen, select the Data Table and click **Open Component Builder**.
2. In the **Properties** tab, under **Data Source**, click **Query**.
3. In **Object API Name**, pick **Opportunity**.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FbjJyf6PdeivV5oqNozZp%2Fdata-table-tutorial-dtref-query-source.png?alt=media" alt="The Query data source on Opportunity with a Stage filter, an Order By on Amount and four mapped columns including Account Name from the parent account" width="320"><figcaption><p>A Query data source with a Stage filter, an Order By on Amount and mapped columns.</p></figcaption></figure>
{% endstep %}

{% step %}

### Keep only the open deals

Under **Filters**, click **Add Condition** and set the Closed field (`IsClosed`) equals `False`.

* **Add Group** combines conditions with AND or OR, for example Stage equals Negotiation/Review OR Amount greater than 100000.
* A condition value can be a flow resource, for example `{!recordId}` to keep the opportunities of the account the flow was launched from.
  {% endstep %}

{% step %}

### Sort and cap the results

1. Under **Order By**, add Close Date, **Direction** ascending.
2. In **Maximum Number of Records**, type `200`. A query never returns more than 50,000 records, whatever you type here.
   {% endstep %}

{% step %}

### Add the columns

Drag Name, Stage, Amount and Close Date from the **Fields** tab onto the table preview. For Account Name, open **Account** in the field list and drag **Account Name**: the query reads the parent field, no formula needed.

The preview loads a sample of up to 20 opportunities and ignores your filters, so closed deals can appear there. See [What the Builder Preview Shows](https://docs.avonnicomponents.com/flow/component-builder/data-sources/builder-preview.md).
{% endstep %}

{% step %}

### Save and test

Click **Done**, save the flow and click **Debug**. The table lists open opportunities only, earliest close date first, each with its account name.
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## Make the query follow the screen

A filter typed under **Filters** is fixed: it does not change when the user picks something else on the screen. To filter the deals by the stage an account executive picks in a Combobox, the filter comes from a formula instead.

{% stepper %}
{% step %}

### Add the Stage picker

On the same screen, add an Avonni [Combobox](https://docs.avonnicomponents.com/flow/flow-components/combobox.md) named `StageFilter` with the [Picklist](https://docs.avonnicomponents.com/flow/component-builder/data-sources/picklist.md) source on Opportunity **Stage**.
{% endstep %}

{% step %}

### Write the filter as a formula

Create a **Formula** resource named `DealFilter`, data type **Text**, that returns the condition. It must keep the open deals rule, because it replaces the whole filter:

```
IF(
  ISBLANK({!StageFilter.value}),
  "IsClosed = false",
  "IsClosed = false AND StageName = '" & {!StageFilter.value} & "'"
)
```

Use the API names of the base object's fields. Text and Id values need single quotes inside the string.
{% endstep %}

{% step %}

### Map the filter

In the Data Table's query, click the **Type of value** button next to **Filters**, choose **Mapped**, and pick `{!DealFilter}`.
{% endstep %}

{% step %}

### Save and test

Click **Done**, save and **Debug**. Pick Negotiation/Review in the Combobox: the table reloads with the open deals at that stage. Clear the Combobox and every open deal comes back.
{% endstep %}
{% endstepper %}

For more patterns (one table filtering another, dependent picklists), see the reactive query tutorials under Related tutorials.

## Advanced Options

Click **Advanced Options** under the query to reach these settings.

| Setting                       | What it does                                                                                                                                                                                                                                                                                                     |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Strip Inaccessible Fields** | Removes from the results the fields the running user cannot access.                                                                                                                                                                                                                                              |
| **System Mode**               | Runs this query in system mode. Use it only when every user of the screen may see every record it returns.                                                                                                                                                                                                       |
| **Additional fields**         | Adds fields to the query on top of those used by the columns and the interactions, for example `Probability` when a later interaction needs it.                                                                                                                                                                  |
| **Query Refresh Emp**         | Reloads the query when a platform event arrives: **Channel Name** is the platform event object, **Key Field Name** and **Key Field Value** limit the refresh to matching events. See the [platform events tutorial](https://docs.avonnicomponents.com/flow/tutorials/platform-events/configuration-tutorial.md). |

To reload the table after a change, from a button or after a dialog flow, use [Refresh Query](https://docs.avonnicomponents.com/flow/component-builder/interactions-panel/refresh-query.md).

## Troubleshooting

<details>

<summary>"No such relation 'Profile' on entity 'User'" for some users only</summary>

The query runs with the running user's permissions. Salesforce hides some relationships, such as `Profile` on User, from users without the matching permission (View All Profiles or View Setup and Configuration). Admins do not see the error. Remove the relationship from the columns and filters, grant the permission, or turn on **System Mode** if every user may see the results. A component that filters on this one's selection shows nothing either, since the selection stays empty.

</details>

<details>

<summary>The table shows fewer records than expected</summary>

Check **Maximum Number of Records**, then the filters. A query never returns more than 50,000 records.

</details>

<details>

<summary>The mapped filter returns nothing or an error</summary>

1. Add a **Display Text** on the screen that shows `{!DealFilter}` and run the flow: you see the exact clause the table receives.
2. Run that clause against the same object in a SOQL tool, for example `SELECT Name FROM Opportunity WHERE IsClosed = false AND StageName = 'Negotiation/Review'`.
3. If the test query fails, fix the formula: quotes, field API names, values that match the field type. If it works and the table still does not filter, [contact support](https://docs.avonnicomponents.com/flow/help/support-and-troubleshooting.md).

</details>

## Related tutorials

* [How to make Data Tables reactive](https://docs.avonnicomponents.com/flow/tutorials/reactive-query-tutorials/how-to-make-data-tables-reactive.md): select an account in one table, see its records in the others.
* [How to create a Combobox-filtered Data Table](https://docs.avonnicomponents.com/flow/tutorials/reactive-query-tutorials/how-to-create-a-combobox-filtered-data-table.md): the Stage picker above, step by step.
* [Build a reactive Data Table using dependent picklists](https://docs.avonnicomponents.com/flow/tutorials/reactive-query-tutorials/build-a-reactive-data-table-using-dependent-picklists.md): two linked pickers drive one query.
* [Refresh Query](https://docs.avonnicomponents.com/flow/component-builder/interactions-panel/refresh-query.md): reload the table after an update.


---

# 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/component-builder/data-sources/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.
