Create an Invoice Template in Salesforce with Dochly
What is a Salesforce invoice template?
A Salesforce invoice template in Dochly is a reusable invoice structure that pulls line items, pricing, billing details, and payment terms directly from Salesforce records at generation time. Every invoice generated from the template is accurate, consistently formatted, and stored as a Salesforce File on the originating record — no manual steps required.
Dynamic line item table
Pulls from Opportunity Products automatically — expands to fit any number of line items without manual adjustment.
Automatic totals
Subtotal, tax, discounts, and total amount pulled directly from Salesforce fields — no manual calculation needed.
Batch generation
Generate invoices for hundreds of Opportunities in a single scheduled Flow run — monthly billing cycles automated entirely.
Automated delivery
Invoices delivered to billing contacts via email automatically — no rep action required after the template is published.
Conditional tax sections
Tax lines appear or hide based on account region, tax-exempt status, or product type — handled by conditional logic.
Stored on the record
Each generated invoice attaches to the Salesforce Opportunity as a File — instantly accessible for audit and re-sending.
Invoice types you can build
Use the same template creation process for any invoice type — the difference is which fields and conditional sections you include.
Before you build
Invoice templates are data-heavy — every field must map to a real Salesforce value. Confirm the following before opening the template editor:
Your invoice line items pull from Opportunity Products (Order Items). Confirm Products and Price Books are configured in your Salesforce org and that sales reps consistently add products to Opportunities.
Identify how tax is stored in your org — a custom Tax__c field on the Opportunity, a formula field, or a tax amount on each line item. This determines how you build the totals section.
Know which Contact record holds the billing contact for each account — this may be a custom field (Billing_Contact__c) or the primary Contact on the Opportunity depending on your org setup.
Decide how invoice numbers are generated — a custom auto-number field on the Opportunity, a formula field, or a sequential number field. This must exist in Salesforce before building the template.
100% native Salesforce invoice generation & automation
Step-by-step: building your invoice template
Create and name the template
Open the Dochly app in Salesforce. Go to Templates → New Template. Name your template clearly — for example "Standard Invoice" or "Recurring Invoice — Monthly". Select Opportunity as the primary object — this gives you access to Opportunity fields, Account fields, Contact fields, and Opportunity Line Items.
See the foundational guide: Create a document template in Salesforce with Dochly
Build the invoice header
The invoice header contains your company branding and the document title. Use a two-column layout — logo on the left, invoice reference details on the right:
Invoice #: {{Opportunity.Invoice_Number__c}}
Invoice Date: {{TODAY | date: "MMMM d, yyyy"}}
Due Date: {{Opportunity.Payment_Due_Date__c | date: "MMMM d, yyyy"}}
For header branding: Build a branded document template
Build the "Bill To" section
The Bill To section identifies the customer being invoiced. Pull billing details from the Account and Contact records associated with the Opportunity:
{{Account.Name}}
{{Contact.FirstName}} {{Contact.LastName}}
{{Account.BillingStreet}}
{{Account.BillingCity}}, {{Account.BillingState}} {{Account.BillingPostalCode}}
{{Account.BillingCountry}}
{{Contact.Email}}
See the full field reference: Add Salesforce merge fields to a document template
Add the invoice details block
Below the Bill To section, add a compact reference block with deal and payment details — often laid out in a 2–3 column grid for clean scanability:
Contract Reference: {{Opportunity.Name}}
Payment Terms: {{Opportunity.Payment_Terms__c}}
Currency: {{Opportunity.CurrencyIsoCode}}
Build the line items table
This is the most important section of any invoice. Use a dynamic repeating table that pulls from Opportunity Products — the table expands to fit however many line items exist on the deal:
---------------------|------|-------------|-----------|--------
{REPEAT OpportunityLineItems}
{{OpportunityLineItem.Name}} | {{OpportunityLineItem.Quantity}} | {{OpportunityLineItem.UnitPrice | currency}} | {{OpportunityLineItem.Discount}}% | {{OpportunityLineItem.TotalPrice | currency}}
{END REPEAT}
Right-align all numeric columns (Qty, Unit Price, Discount, Amount) and left-align the Description column. Add 6–8px cell padding for readability.
Build the totals section
The totals section appears below the line items table, right-aligned. It breaks down subtotal, discounts, tax, and the final amount due. This is how the totals block maps to Salesforce fields:
| Subtotal | {{Opportunity.Subtotal | currency}} |
| Discount | - {{Opportunity.TotalOpportunityQuantity}} % |
| Tax ({{Opportunity.Tax_Rate__c}}%) | {{Opportunity.Tax_Amount__c | currency}} |
| Shipping | {{Opportunity.Shipping_Amount__c | currency}} |
| Total Amount Due | {{Opportunity.Amount | currency}} |
The exact field names for Subtotal, Tax, and Shipping depend on how your Salesforce org is configured. If these custom fields don't exist, work with your admin to add them. Standard Opportunity fields include Amount and TotalOpportunityQuantity.
Handle tax with conditional logic
Not every invoice needs a tax line. Use conditional logic to show or hide tax sections based on account region, tax-exempt status, or product type:
Tax ({{Opportunity.Tax_Rate__c}}%): {{Opportunity.Tax_Amount__c | currency}}
{END IF}
{IF Account.BillingCountry = "United Kingdom"}
VAT Number: {{Account.VAT_Number__c}}
VAT (20%): {{Opportunity.VAT_Amount__c | currency}}
{END IF}
{IF Account.BillingCountry = "Australia"}
GST (10%): {{Opportunity.GST_Amount__c | currency}}
{END IF}
Add payment instructions
Every invoice needs clear payment instructions. This section is typically static — your bank details, payment methods accepted, and any online payment portal link. Add due date and late payment terms pulled from Salesforce:
Payment Due: {{Opportunity.Payment_Due_Date__c | date: "MMMM d, yyyy"}}
Payment Terms: {{Opportunity.Payment_Terms__c}}
Bank Transfer:
Bank Name: [Your Bank Name]
Account Name: [Your Company Name]
Account Number: [Your Account Number]
Sort Code / SWIFT / IBAN: [Your Details]
Reference: {{Opportunity.Invoice_Number__c}}
Add footer and legal notices
The invoice footer should include your company's registered details, VAT or tax registration numbers where required, and any late payment notice. Use the special page number merge fields for multi-page invoices:
{IF Account.BillingCountry = "United Kingdom"}
VAT Registration: [Your VAT Number]
{END IF}
Page {{PAGE}} of {{TOTAL_PAGES}}
Preview, test, and publish
Test the invoice template from multiple real Opportunity records before publishing. Verify these specific scenarios:
- An Opportunity with multiple line items (5+) — confirm table expands correctly
- An Opportunity with a discount — confirm discount line appears in totals
- A UK account — confirm VAT section appears and VAT number shows
- A tax-exempt account — confirm tax section is hidden
- An Opportunity with a missing due date field — confirm no "null" appears
For troubleshooting issues: Template editor troubleshooting guide
Batch invoice automation
The most powerful use of an invoice template is batch automation — generating invoices for all eligible Opportunities in a single scheduled run instead of one by one. This is how a monthly invoice run works end to end in Salesforce:
A time-triggered Salesforce Flow collects all Opportunities with Stage = "Closed Won" and Invoice_Status__c = "Pending" closed in the previous 30 days.
The Flow triggers Dochly to generate invoices for all collected Opportunities simultaneously — one invoice per record, using the published invoice template.
Each invoice is generated with that Opportunity's live data and attached as a Salesforce File on the respective record — no manual intervention required.
Dochly emails each invoice to the billing contact on the Opportunity automatically — with the invoice PDF as an attachment.
The Flow updates Invoice_Status__c from "Pending" to "Sent" on each processed Opportunity — giving finance teams a live view of invoice status without leaving Salesforce.
Batch invoice automation is the most common high-volume use case for Dochly across finance and operations teams. A sales team processing 200 invoices per month manually (20–30 minutes each) can reduce that to a single scheduled job that runs in minutes. See the guide on managing multiple document templates for organizing invoice template variants by billing cycle or region.
Invoice template best practices
- Always include an invoice number field — create an auto-number field on the Opportunity object if one doesn't exist. Invoices without unique reference numbers create reconciliation problems for your customers.
- Include both invoice date and due date — pull invoice date from TODAY and due date from a custom Payment_Due_Date__c field. Never leave due date blank on a generated invoice.
- Use conditional logic for tax — different regions, tax-exempt accounts, and product types all have different tax requirements. Handle all variants in one template rather than creating separate invoice templates per region.
- Include your company's legal registration details — especially for VAT/GST invoices, include registration numbers in the footer. Invoices missing required legal details may not be accepted by your customers' accounts payable teams.
- Version your invoice template — when your pricing structure or legal details change, create a new version rather than overwriting. Historical invoices must reflect the terms in effect when they were issued. See editing and updating existing templates.
- Validate required fields before generation — add a Salesforce validation rule or Flow check to ensure Invoice_Number__c and Payment_Due_Date__c are populated before an invoice can be generated.
Frequently asked questions
Your invoice template is ready to generate accurate, tax-compliant invoices automatically from any Salesforce Opportunity. Next steps: Edit and update an existing template · Manage multiple templates · Troubleshooting guide
Rated 5 stars · Native Salesforce app · Free to install