Verification in progress Differs from official docs Test scripts included

Returns the first matching record from a Sales Cloud object, a marketing object or a data graph.

Syntax

{{queryFirst object type [...options]}}

Returns object.

Parameters

Name Type Required Description
object string Yes The API name of the target object, marketing object, or data graph.
type string Yes The data source type: CRM, MO, or DG.
options any No, repeatable Named arguments such as fields, where, params, sortBy, id.

Example

Tested in Marketing Cloud Next emails on 2026-11-25, one call per email, against a test marketing object zzprobecoupons__mo with the key field CouponCode__c:

  • {{get (queryFirst type="MO" object="zzprobecoupons__mo" CouponCode__c="PROBE0001") "IsClaimed__c"}} renders false, the stored value.
  • Without the key filter (the call on its own, inside #with, or inside get): the preview fails with HTTP 500 and no message.
  • A CRM call inside {{#if false}}…{{/if}} is accepted when the email is saved.

On the Contact object (type="CRM"), with the expected record taken from a SOQL query of the same org:

  • {{get (queryFirst type="CRM" object="Contact" fields="LastName" where="pi__score__c = :s" params=(hash s=82)) "LastName"}} renders the last name of the one matching contact.
  • With where="pi__score__c > :s" params=(hash s=200), sortBy="pi__score__c DESC" returns the contact with the highest score and sortBy="pi__score__c ASC" the one with the lowest.
  • When nothing matches (s=1), [{{get (queryFirst …) "LastName"}}] renders [] and the email renders normally.

This is the Handlebars counterpart of AMPscript Lookup: Lookup("zzprobecoupons__mo","IsClaimed__c","CouponCode__c","PROBE0001") rendered the same false.

Thanks to Nobuyuki Watanabe’s SFMC Tips #327 for the get (queryFirst type="MO" …) "Field" pattern as the replacement for AMPscript Lookup, and SFMC Tips #313 for the hint that every key field of a marketing object belongs in the filter.

Show Next test script
<!-- Marketing Cloud Next test script for the queryFirst helper. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[gated] got=[{{#if false}}{{queryFirst object="Contact" type="CRM" fields="Id"}}{{/if}}gated]</p>
<p>c2 expect=[false] got=[{{get (queryFirst type="MO" object="zzprobecoupons__mo" CouponCode__c="PROBE0001") "IsClaimed__c"}}]</p>
<p>c3 expect=[Blau] got=[{{get (queryFirst type="CRM" object="Contact" fields="LastName" where="pi__score__c = :s" params=(hash s=82)) "LastName"}}]</p>
<p>c4 expect=[Adelson] got=[{{get (queryFirst type="CRM" object="Contact" fields="LastName" where="pi__score__c > :s" params=(hash s=200) sortBy="pi__score__c DESC") "LastName"}}]</p>
<p>c5 expect=[Jones] got=[{{get (queryFirst type="CRM" object="Contact" fields="LastName" where="pi__score__c > :s" params=(hash s=200) sortBy="pi__score__c ASC") "LastName"}}]</p>
<p>c6 expect=[[]] got=[[{{get (queryFirst type="CRM" object="Contact" fields="LastName" where="pi__score__c = :s" params=(hash s=1)) "LastName"}}]]</p>
<p>c7 expect=[twelve] got=[{{get (queryFirst type="MO" object="zzprobenumkey__mo" CouponNo__c=12) "Label__c"}}]</p>
<p>c8 expect=[70.0] got=[{{get (queryFirst type="MO" object="zzprobenumkey__mo" Label__c="seventy") "CouponNo__c"}}]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
{{get (queryFirst object="zzprobecoupons__mo" type="MO") "CouponCode__c"}}

<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
{{get (queryFirst type="MO" object="zzprobenumkey__mo" Label__c="group" sortBy="Points__c DESC") "CouponNo__c"}}

Differs from official docs

  • On a marketing object (type="MO"), the call needs at least one inline filter, such as KeyField__c="value"; a field other than the key works too. Without one, the preview fails with HTTP 500 and no message, although the reference lists only object and type as required. sortBy fails the same way. Details

Marketing Cloud Next

See also