---
schema_version: "1"
id: a9c2e2883cf2240ecfd3bbff01d288a0f681357c465b25fd7f097b1bf366488b
title: "Handlebars Helper Function: query"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/data/mcn-handlebars-reference-data-query.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-data-references/mcn-handlebars-reference-data-query.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5e0e87be9992d10081cf0954ec8b8ff1d8405663933403b81240ed4c1b527dbf
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# Handlebars Helper Function: query

Retrieves multiple records from Sales Cloud or marketing object data sources. Use this helper to fetch arrays of records based on criteria that you specify.

## Availability

This helper is available in the Summer ’26 release of Marketing Cloud Next.

## Syntax

```handlebars
{{query type=CRM|MO object=OBJECT_NAME
  [id=SALESFORCE_ID] [fields=FIELD_1, ...FIELD_N]
  [sortBy=FIELDNAME ASC|DESC] [limit=LIMIT]
  [where=FILTER] [params=PARAMS]}}
```

## Parameters

| Parameter | Type    | Description                                                                                                                                                                                                         |
| --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `object`  | String  | Required. The API name of the target object. Specify as a named parameter with a value equal to the name of the object to query.                                                                                    |
| `type`    | String  | Required. The type of data source to query. Specify as a named parameter with one of these values: `CRM` (for Sales Cloud objects) or `MO` (for marketing objects).                                                 |
| `fields`  | String  | A comma-separated list of field names to retrieve from the matching records.                                                                                                                                        |
| `id`      | String  | The Salesforce ID of the target object. Use this parameter only when `type` is `CRM`.                                                                                                                               |
| `limit`   | Integer | The maximum number of records to return in the query. If the value of `type` is `CRM`, the default value is 100.                                                                                                    |
| `params`  | Object  | Parameter values for `where` placeholders. Every parameter name in the `where` clause must have a corresponding key. See [Params Values](#params-values).                                                           |
| `sortBy`  | String  | Indicates the sort order to apply to results. Specify a field name followed by `ASC` (ascending order) or `DESC` (descending order). Use this parameter only when `type` is `CRM`. The default sort order is `ASC`. |
| `where`   | String  | A filter for the query. Use `:paramName` placeholders. Can’t be combined with inline field conditions or the `id` parameter. See [Where Clause Syntax](#where-clause-syntax).                                       |

### Where Clause Syntax

The `where` parameter supports these elements:

- Operators: `=`, `!=`, `<`, `>`, `<=`, `>=`, `LIKE`
- Logic: `AND` and `OR`
- Placeholders: `:paramName` values that match keys in the `params` object

You can use parentheses to create logical groupings. For example, to add a filter that includes active records and either the Revenue value or the CreationDate value is greater than a specified parameter, use `Status = "Active" AND (Revenue > 100000 OR CreationDate > "2025-01-01")`.

### Params Values

Use the [hash](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-data-references/mcn-handlebars-reference-data-hash.md) function to specify parameters. This example uses the `hash` function to create an object with two properties: `name` and `status`. The `where` statement then refers to these parameters.

```handlebars
{{query
  type="CRM"
  object="Account"
  fields="Name"
  where="Name LIKE :name AND Status = :status"
  params=(hash name=firstName status="Active")
}}
```

## Return Value

The function returns an array of matching records. If no records match the criteria, it returns an empty array `[]`.

## Usage Examples

This example retrieves results from the Contact object that match a specific ID in Sales Cloud.

```handlebars
{{query type="CRM" object="Contact" id="001xx"}}
```

### Sorting and Limiting Results

This example retrieves records from the Contact object and sorts them in ascending order by the `LastName` field. It then returns the first 10 results.

```handlebars
{{query type="CRM" object="Contact" sortBy="LastName " limit=10}}
```

### Filtering with the Where Clause

This example retrieves objects from the Account object where the value of the `minRev` property is greater than 1,000,000 and the value of the `status` property is `Active`.

```handlebars
{{query
  type="CRM"
  object="Account"
  where="Revenue > :minRev AND Status = :status"
  params=(hash minRev=1000000 status="Active")
}}
```

## See Also

- [queryFirst](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-data-references/mcn-handlebars-reference-data-queryfirst.md)
- [hash](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-data-references/mcn-handlebars-reference-data-hash.md)
- [each](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/objects/mcn-handlebars-reference-objects-each.md)
- [length](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/utility/mcn-handlebars-reference-utility-length.md)
