Named Query Working Examples
Use copy-paste named query examples to display aggregates, target specific rows, and combine filters with offsets.
Use these examples when you already understand the basic named query structure and want patterns you can reuse.
Example 1: Display an aggregate value
Use an aggregate named query when you need a count or sum in plain text.
<!--{{!
<lineitemsSOQL>
<queryname>LineItemStats</queryname>
<soql>
SELECT COUNT(Id) cid, SUM(TotalPrice) asum
FROM OpportunityLineItem
WHERE OpportunityId = '{{!Opportunity.Id}}'
</soql>
</lineitemsSOQL>
}}-->This opportunity has {{!LineItemStats.cid}} line items totaling ${{!LineItemStats.asum #,###.##}}.Use aliases like cid and asum in the SELECT clause.
Then reference those aliases in the merge field.
Example 2: Use offset to pull specific rows
Use offset when your query returns multiple rows and you want one specific result.
offset="1" returns the first row.
offset="2" returns the second row.
Example 3: Use filter with offset
Use filter when you want reusable conditions inside one named query.
If your sample data uses smaller values, lower the filter threshold.
Keep going
Review Reference: Named Query Syntax for the full tag and attribute reference
Review How to: Advanced Data Retrieval with Named Queries for more advanced patterns
Last updated
Was this helpful?

