> For the complete documentation index, see [llms.txt](https://university.gonexa.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university.gonexa.fr/doc/en/advanced-features/custom-query/custom-query-multiple-results.md).

# Create a custom query with multiple results

With a custom query that returns multiple results, the chosen object may or may not be linked to the main object. It will be displayed in a table in the document.

* Go to the Gonexa Assistant component and click "Custom query"
* Choose the relevant Salesforce object. The label is filled in by default, but you can change it for more clarity in the template
* Select "All records"; a few additional fields appear. If the object you want to use is linked to the main object of the document template, specify the relationship between the two in the "Link to main object" field. If there is no link, you can leave this field empty
* You can then add a filter and a sort order on the records to retrieve, if needed

![Custom query - All records](https://4198981723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYUzkIngX1MnHE8kOJDR%2Fuploads%2Foo127s5B7eswOwLudYCR%2Frequete-personnalisee-7.png?alt=media)

## Example of a custom query linked to the main object

**Add a table for a related object to the document**

The main object is Account, and we want to display the campaign members that match the account's contacts.

* Choose the "Campaign Member" object
* Select "All records"
* In "Link to main object", navigate up the relationship to select "Account"
* From the "Campaign Member" object, navigate up to the "Contact" object to reach the "Account"
* Add a table to your document template and insert the tags into it

## Example of a custom query with no link to the main object

**Add a filtered table**

You want to display all the available Options-type products in Salesforce and add them to a table.

* Choose the "Product" object
* Select "All records"
* Since you want to display all available products, leave the "Link to main object" field empty
* In the "Filter" section, add a filter where type = "Options"
* Add a table to your document template and insert the tags into it


---

# 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://university.gonexa.fr/doc/en/advanced-features/custom-query/custom-query-multiple-results.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.
