Salesforce Field Types and Formatting
Salesforce has many field types, and each should be formatted differently in your Viewer templates. This page shows how to format the most common field types for professional documents.
Quick reference by field type
| Field Type | Best Helper | Format Example | Example Output |
|---|---|---|---|
| Date | moment | {{moment date format="DD/MM/YYYY"}} | 04/02/2024 |
| DateTime | moment | {{moment datetime format="DD/MM/YYYY HH:mm"}} | 04/02/2024 15:30 |
| Currency | currencyIcon + number | {{currencyIcon "USD"}} {{number amount "0,0.00"}} | $ 15,250.50 |
| Number | number | {{number value "0,0.00"}} | 1,500.50 |
| Percent | number | {{number percent "0.00"}}% | 85.50% |
| Checkbox | showCB | {{showCB checkbox}} | ✓ or ✘ |
| Long Text Area | nl2br | {{nl2br longtext format="PDF"}} | Preserves line breaks |
| Rich Text | docxHtml | {{docxHtml richtext}} | Formatted text |
| Plain text | {{email}} | user@example.com | |
| Phone | Plain text | {{phone}} | (555) 123-4567 |
| Picklist | Plain text | {{picklist}} | Selected value |
Date fields
Salesforce field: Any Date type field (e.g., Account.BillingDate)
Format a date
Expected output (if date is Feb 4, 2024):
04/02/2024
Common date formats
Expected output:
2024-02-04
Format with text
Expected output:
Document date: February 04, 2024
DateTime fields
Salesforce field: Any DateTime type field (e.g., Opportunity.CreatedDate)
Format datetime with time
Expected output:
04/02/2024 15:30
Format with readable text
Expected output:
Created on February 04, 2024 at 03:30 PM
Currency fields
Salesforce field: Any Currency type field (e.g., Opportunity.Amount)
Basic currency with symbol
Expected output (if Amount = 15250.50):
$ 15,250.50
Dynamic currency from field
Expected output:
€ 15,250.50
Currency with localization
Expected output:
€ 15.250,50
Use en-US, de-DE, fr-FR, it-IT, etc. to format numbers with local conventions (comma vs period for decimals).
Number fields
Salesforce field: Any Number or Decimal type field (e.g., Account.NumberOfEmployees)
Format with thousands separator
Expected output (if value = 1500000):
1,500,000
Number with decimals
Expected output (if value = 99.5):
99.50
number0 for safetyUse number0 instead of number to show "0" instead of empty string for null values.
Percent fields
Salesforce field: Any Percent type field (e.g., Opportunity.Probability)
Display as percentage
Expected output (if value = 85.5):
85.50%
No decimals
Expected output:
85%
Checkbox fields
Salesforce field: Any Checkbox type field (e.g., Account.Active__c)
Show as checkmark/X
Expected output:
Status: ✓ (if checked) or Status: ✘ (if unchecked)
Show as yes/no text
Expected output:
Active (if checked) or Inactive (if unchecked)
Long Text Area fields
Salesforce field: Any Long Text Area type field (e.g., Account.Description)
Preserve line breaks
This ensures that line breaks entered in Salesforce are preserved in the PDF or Word document.
Expected output (preserves original line breaks):
Line 1
Line 2
Line 3
Always use nl2br for long text fields that may contain line breaks. Without it, all text appears on one line.
Rich Text fields
Salesforce field: Any Rich Text Area type field (e.g., Account.RichTextDescription__c)
For Word documents, use the docxHtml function to properly convert HTML formatting to native Word formatting. This ensures that bold, italic, lists, links, and other HTML elements are rendered correctly in the Word document.
Basic Rich Text to DOCX
With content validation
- Case sensitive: Must use
docxHtml(notdocxhtmlor other variations) - Content validation: The content cannot be null or blank. Always wrap with
isTruthyto validate before passing todocxHtml - No embedded images:
docxHtmldoes not support embedded images - Testing: Verify content formatting in actual Word documents before deploying to production
The docxHtml function automatically transforms HTML tags to Word-native formatting (bold → bold, italic → italic, lists → bullet points, etc.).
Email fields
Salesforce field: Any Email type field (e.g., Contact.Email)
Display as plain text
Expected output:
Contact: john.smith@example.com
Create a mailto link (use in HTML template)
Expected output:
Send email (clickable link)
Phone fields
Salesforce field: Any Phone type field (e.g., Account.Phone)
Display as plain text
Expected output:
Phone: (555) 123-4567
Salesforce stores phone numbers in various formats. Consider standardizing the format in your template or in a custom field.
Picklist fields
Salesforce field: Any Picklist or Multi-select Picklist type field (e.g., Opportunity.StageName)
Display picklist value
Expected output:
Status: Closed Won
Best practices
- Always test with real data — Test your formatting with actual Salesforce records to catch edge cases
- Handle null/empty values — Use
{{#if}}to show alternative text for missing data - Use the right helper — Match the helper to the field type (dates →
moment, numbers →number, etc.) - Localize numbers and dates — Use locale codes for international documents
- Format consistently — Keep formatting conventions the same across all templates
- Preserve special formatting — Use
nl2brfor long text and triple braces for rich text
Related helpers
- Data Formats and Date Manipulation – Deep dive into date helpers
- Viewer Number Helpers – Advanced number formatting
- Currency Icon Helper – Display currency symbols
- Viewer String Helpers – Format text fields including
nl2br - Handlebars Comparison Helpers – Conditional formatting with
{{#if}}