Pattern · Integration
Document generation on the pricing context
Generate a quote document without building a data-extraction layer, by reusing the context the pricing engine already uses.
The problem
A quote has to come out as a branded PDF. The classical approach builds an extraction layer to feed the template — a layer that then has to be maintained alongside every change to the quote model.
Context
An existing Word template, and a quote model that the pricing engine already reads through a context definition.
Recommended architecture
Point the document template at the same context definition the pricing procedure uses. The data contract already exists and is already maintained, so the extraction layer disappears entirely.
Tokens in the template are then simply the names of context attributes.
Implementation
- Bind the template to the context rather than to a bespoke extract.
- Name every token exactly like its attribute. Custom attributes keep their
__csuffix in the token. - Tag every attribute you intend to use. An attribute is only usable as a token if it carries a context tag. Inherited attributes are already tagged and work immediately; custom ones must be mapped, tagged and republished — which is exactly why “only the inherited ones work” is the first symptom you will see.
- Format dates and resolve names before the template sees them. A raw date renders as an ISO timestamp, and the context exposes an account reference rather than the account name.
Trade-offs
Reusing the pricing context means document changes touch a definition that pricing also depends on. Additive changes are safe; anything else deserves a sandbox first.
In exchange there is no second data layer to maintain, and the document and the price can never disagree about what the quote contains.
Watch out
- Pick the total that means net. One total on the context is the sum of list prices and will overstate the document.
- Replacing a template file can change its identifier, which breaks any button that holds the identifier. Uploading a new version of the same file keeps it stable.
- A new field may not appear in the designer until the page is reloaded.
Salesforce components
Salesforce resources
Architecture
Guide