Nested Queries

The Avonni Nested Query Data Source allows you to retrieve hierarchical data from your Salesforce org—specifically, parent records and their related child records—in a single query. This is ideal for displaying data in components like the Avonni Tree, which requires a nested structure.


Core Concepts

What is a Nested Query?

A Nested Query retrieves a list of parent records and, for each parent record, also retrieves its associated child records. This creates a nested data structure reflecting your Salesforce data's parent-child relationships. This differs from a standard Query, which retrieves a flat list of records.

When to Use Nested Queries

Use Nested Queries when you need to display hierarchical data, typically in components like:

  • Avonni Tree: The primary use case, as the Tree component is designed to visualize hierarchical data.

  • Other components might benefit from displaying nested relationships in the future.


Managing Nested Queries

Important Note: Nested Query Configuration Updates

Creating a Nested Query

You can create a new Avonni Nested Query in two ways:

  • Via the Resources Button:

    1. Click the Resources button (usually located in the page editor or component panel).

    2. Select the option to create a new Nested Query Resource.

  • From an Avonni Component (e.g., Tree):

    1. Select the Avonni component (e.g., Tree) to connect to the nested query.

    2. In the component's properties panel, look for a button or link labeled "Create a Nested Query" or "New Nested Query". Click it.

Editing a Nested Query

You can modify an existing Avonni Nested Query in two ways:

  • From the Resources Menu:

    1. Click the Resources button.

    2. Locate the Nested Query you want to edit in the list of resources.

    3. Select the option to edit the Nested Query (this might be an "Edit" button, a pencil icon, or clicking the query name).

  • From an Avonni Component:

    1. Select the Avonni component (e.g., Tree) currently using the Nested Query.

    2. Find the section related to the data source or query in the component's properties panel.

    3. Look for an option to edit the Nested Query (this might be an "Edit" button, a pencil icon, or similar).

Important Note


Configuring Nested Queries

Configuring a Nested Query involves defining both the parent query (to retrieve the top-level records) and the child query (to retrieve the related records for each parent).

Parent Query Configuration

The parent query defines the top-level records you want to retrieve. This is similar to configuring a standard Query:

  • Object: Select the Salesforce object for the parent records (e.g., Account).

  • Fields: Choose the fields you want to retrieve from the parent object.

  • Filters (Optional): Add filters to limit the parent records retrieved (e.g., Type equals 'Customer'). You can use both static and reactive filters here.

Child Query Configuration

The child query defines how to retrieve the related records for each parent record.

  • Object: Select the Salesforce object for the child records (e.g., Contact).

  • Fields: Choose the fields you want to retrieve from the child object.

  • Relationship Field: Crucially, you'll need to specify the field on the child object that relates it to the parent object (e.g., AccountId on the Contact object). This is how the Nested Query knows which child records belong to which parent record.

  • Filters (Optional): You can add filters to refine the child records retrieved further. You can even use reactive filters here, referencing attributes of the parent record. For example, you could filter Contacts to only show those with a Status of 'Active' for each selected Account.

Example: Accounts and Contacts

To display a tree of Accounts and their related Contacts:

  1. Create a Nested Query Resource.

  2. Parent Query:

    • Object: Account

    • Fields: Id, Name (and any other Account fields you want to display)

  3. Child Query:

    • Object: Contact

    • Fields: Id, FirstName, LastName, Email

    • Relationship Field: AccountId (This links the Contact to its parent Account)

  4. Connect the Nested Query to an Avonni Tree component.

  5. Configure the Tree component to display the desired fields from parent (Account) and child (Contact) records.


Reactive Nested Queries

Nested Queries can also be reactive, just like standard Queries. This means that the data displayed can update dynamically based on user interactions or changes in other components.

  • Reactive Filters in Parent Query: You can use reactive filters to control which top-level records are displayed in the parent query.

  • Reactive Filters in Child Query: You can use reactive filters in the child query, and these filters can even reference attributes of the parent record. This allows for very dynamic and context-aware data displays. For example, you could have a dropdown that controls which type of Contacts are shown for each Account.

Last updated

Was this helpful?