Using SOQL query merge fields in Excel allows Salesforce data to flow directly into structured templates with accuracy and consistency. This approach ensures that Excel outputs reflect real-time Salesforce records without manual data entry. In this quick guide, we have provided steps to apply the correct merge field syntax, use query aliases properly, and generate clean Excel documents through Salesforce document generation, while maintaining strong document management workflows.
Step 1: You can use the SOQL query in the Excel template by following the syntax below:
Merge Field Syntax
&=${{QueryAlias.mergeFieldApiName}}
Example SOQL Query
SELECT Id, LastName, FirstName, Name FROM Contact WHERE Account.Id = ‘{pv0}’
In this query, the alias used is ‘query’.
Use the following merge field syntax in the Excel file to display data from the query.
| Last Name | First Name | Full Name |
|---|---|---|
| &=${{query.LastName}} | &=${{query.FirstName}} | &=${{query.Name}} |
&=${{query.LastName}}
&=${{query.FirstName}}
&=${{query.Name}}
Note:
- Ensure that the Query Alias used in the Excel template matches the alias defined in the query.
- The merge field API names must exactly match the fields used in the SOQL query.
- This syntax is mandatory for proper data rendering in Excel output.
- Please refer to the attached screenshot for a visual reference.

Step 2: After completing the above step, upload the Excel template to the Add Template section. The screenshot below shows the generated Excel document output.

Conclusion
Applying SOQL query merge fields correctly ensures your Excel templates always render accurate Salesforce data. When aliases and field API names align, document outputs are generated without errors or rework. This process keeps Excel documents structured, consistent, and ready for business use. Overall, it strengthens Salesforce document generation by enabling dependable and automated document creation at scale.
Frequently Asked Questions
Related Blogs
How Universities Reduce Administrative Work by 75% Using Automated Document Generation
Universities have a lot going on. Admissions, enrollment, student records, certificates, agreements, invoices, reports, and then there are probably ten…
How Manufacturing Companies Can Automate Purchase Orders Using Salesforce
Purchase orders look simple from the outside. A few details, some product information, supplier details, approval, and done. But anyone…
How to Configure Document Solutions Parameters Using a Formula Field in Salesforce
Managing multiple document templates in Salesforce can become challenging when different records require different document outputs. With document solutions, users…