> 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.md).

# Custom query

Custom queries let you navigate the Salesforce object model without necessarily having a link with the starting context.

{% hint style="info" %}
**Prerequisites**

* Have already configured a main template
* Have a configured main object
* Master the basics of SOQL queries
  {% endhint %}

## What is it?

**What is a custom query?**

A custom query adds **a second entry point to the data model**, in addition to the main object. It gives you access to objects that have no direct link with it. This is useful in the rare cases where the data model does not let you navigate to the desired data.

## Why use a custom query?

**When should you use a custom query?**

When you want to display data from an object that is **inaccessible** from the main object, that is, an object with no link to the main object.

If the main object is Contact, some objects can be accessed without restriction, while others are isolated and unreachable:

* ✅ Their account (parent object)
* ✅ Their cases (child object)
* ✅ The account owner (parent object)
* ❌ The training session
* ❌ The account's opportunities

**Data model without a custom object**

![Data model without a custom object](https://4198981723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYUzkIngX1MnHE8kOJDR%2Fuploads%2FgAU4GGp79Jivva2kuY4v%2Frequete-personnalisee-1.png?alt=media)

**Solution:** Add a custom query, which creates a second starting point, in other words a new main object, giving you access to the previously unreachable information.

## In this section

* [Create a custom query with a single result](/doc/en/advanced-features/custom-query/custom-query-single-result.md)
* [Create a custom query with multiple results](/doc/en/advanced-features/custom-query/custom-query-multiple-results.md)


---

# 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.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.
