Document Generation for Salesforce: the User Guide


The DocGen user guide is live. Here is the short version: how DocGen turns a Word or Google Docs template into a finished document on any Salesforce record, and the handful of rules that account for most first-template problems.
Summary
The DocGen user guide is live. It covers everything needed to go from a Word or Google Docs template to a finished document on any Salesforce record: quick start, template tokens, loops for related records, the SOQL query checklist, and a troubleshooting table for when a token prints blank.
This post is the short version. It walks through how DocGen works, the three moving parts, and the handful of rules that account for most of the problems people hit when building their first template.
What is DocGen?
DocGen creates editable Word documents straight from Salesforce records. Order forms, quotes, letters, account summaries. One click on the record page, and the finished document is saved against the record and opened for review.
Everything runs inside Salesforce, built in Apex and Lightning Web Components. No middleware, no external service, and your data never leaves the platform.
Why we built it
We kept hitting the same problem ourselves, and customers flagged it too: copying Salesforce data by hand into order forms and other outbound documents. We wanted a quick, native way to produce documents that can still be edited afterwards. So we built one.
The editable part is the bit that gets overlooked. Plenty of tools produce a PDF, which is right for something being sent for signature and wrong for something a salesperson needs to tweak the terms on before it goes out. DocGen produces .docx by default and PDF when you want it.
The three moving parts
DocGen is simpler than it first appears. There are three things, and understanding how they relate is most of the learning curve.
- A template: an ordinary .docx document, designed in Microsoft Word or Google Docs, with merge tokens such as {{Account.Name}} wherever data should appear.
- A SOQL query: tells DocGen which fields to fetch from the record and its related records.
- The DocGen Button: a Lightning component on the record page that ties the template and the query together.
When a user clicks the button, DocGen runs the query for the current record, replaces each token with its value, repeats table rows for related records, and saves the result to the record's Files.
A working button in about ten minutes
- Install or upgrade the RavenApps package from AgentExchange or the Package Version page.
- Create a .docx template in Word or Google Docs, or start from one of the sample templates.
- Edit the record page in Lightning App Builder and add the DocGen: Manager and DocGen Button components.
- Upload the template through DocGen: Manager, which saves it into the DocGen Templates file library.
- Configure the button: refresh the template list, select your template, add your SOQL query, and set the component name, which is the label users see.
- Save the page, open a record, and click the button.
The template library ships with ready-made samples, including an Order Form, Invoice, Non-Disclosure Agreement, Master Services Agreement, Inventory list and Project Kickoff. Copying a sample is the quickest way to start a new template.
Tokens, in one paragraph
Wrap a field's API name in double curly braces. Dot notation reaches parent records, so {{Account.Name}} works, and so does a field through a custom lookup using the relationship name. Custom fields work the same way with their API name. Currency fields print with their symbol and two decimal places, numbers drop unnecessary trailing decimals, and compound address fields print as a multi-line block rather than a run-on line.
There is one rule behind most support questions: every field used in the template must also appear in the SOQL query. A token whose field is not queried renders as blank.
Repeating rows for related records
To list related records, such as products on an Opportunity, wrap a table row in START and END markers named after the child relationship in your query. DocGen repeats that row once per related record, with tokens inside the loop referring to fields on the child.
Two things to keep right: the markers must sit in the same table row as the tokens they wrap, and the header row and any totals row must sit outside the loop. Most "only one line item appears" reports come down to one of those two.
The query checklist
Write the query against the object the button sits on. DocGen runs it for the current record automatically, so there is no need for a WHERE clause on the record Id.
- Every token in the template has a matching field in the query
- Subquery names use the child relationship name, plural, and match the START and END markers exactly
- Include CurrencyIsoCode wherever currency fields appear, in multi-currency orgs, in the main query and in every subquery
- Add ORDER BY inside a subquery to control row order
- Test the query in Developer Console or the Salesforce CLI first, with a temporary WHERE clause on a record Id
The template rules worth knowing before you start
- Open documents in the app you designed in. Word and Google Docs lay out .docx files slightly differently, including spacing, table widths and page breaks. If your team works in Google Docs, design the template there.
- Type each token in one go. If spell-check or autocorrect splits a token across formatting runs, it will print literally. Delete it and retype it without stopping.
- Use tables for layout. Borderless tables give clean, aligned label and value blocks.
- Keep a test record with every field populated, so you can check the full layout in one click.
- Embedded fonts carry through to the generated document, as long as they are TrueType or OpenType.
Permissions and sharing
DocGen runs with the clicking user's access. Users need access to the DocGen Templates file library, read access to every object and field in the query, and edit access to the record so the generated file can be attached to it.
Because templates and outputs are standard Salesforce Files, your existing sharing, storage and retention settings apply with no extra configuration. There are no custom objects to secure.
Multiple documents on one record
Add a separate DocGen Button component for each document type, for example Order Form, Quote and Welcome Letter. Each has its own template, query and label. DocGen: Manager is an admin tool, so it is worth using Lightning App Builder's component visibility settings to show it only to admins, leaving everyday users with just the buttons.
One package, one upgrade
DocGen ships in the same managed package as Grids, so there is a single RavenApps package to install and upgrade. Existing Grids customers get DocGen by upgrading, with nothing extra to install, and it can be installed in a sandbox with no trial clock and no usage limits.
Useful Links
- Install, Upgrade and Package Versions
- DocGen for Salesforce
- AppExchange Listing & Reviews
- RavenApps on YouTube
- Book a Call
Thank You
Thanks for reading. If you have a document your team still produces by hand, bring it to a call and we will build the template against your own data. Book a Call or Contact Us.
40+ features to power up your workflows

