Handlebar 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 (API version 67.0).

Syntax 

1{{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 

ParameterTypeDescription
fieldsStringA comma-separated list of field names to retrieve from the matching records.
idStringThe Salesforce ID of the target object. Use this parameter only when type is CRM.
limitIntegerThe maximum number of records to return in the query. If the value of type is CRM, the default value is 100.
objectStringRequired. The API name of the target object.
paramsObjectParameter values for where placeholders. Every parameter name in the where clause must have a corresponding key. See Params Values.
sortByStringIndicates 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.
typeStringRequired. The type of data source to query. Possible values: CRM (for Sales Cloud objects) or MO (for marketing objects).
whereStringA 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 

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

1{{query type="CRM" object="Account" fields="Name"
2  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.

1{{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.

1{{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.

1{{query type="CRM" object="Account"
2  where="Revenue > :minRev AND Status = :status"
3  params=(hash minRev=1000000 status="Active")}}

See Also