Skip to main content

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 TypeBest HelperFormat ExampleExample Output
Datemoment{{moment date format="DD/MM/YYYY"}}04/02/2024
DateTimemoment{{moment datetime format="DD/MM/YYYY HH:mm"}}04/02/2024 15:30
CurrencycurrencyIcon + number{{currencyIcon "USD"}} {{number amount "0,0.00"}}$ 15,250.50
Numbernumber{{number value "0,0.00"}}1,500.50
Percentnumber{{number percent "0.00"}}%85.50%
CheckboxshowCB{{showCB checkbox}}✓ or ✘
Long Text Areanl2br{{nl2br longtext format="PDF"}}Preserves line breaks
Rich TextdocxHtml{{docxHtml richtext}}Formatted text
EmailPlain text{{email}}user@example.com
PhonePlain text{{phone}}(555) 123-4567
PicklistPlain text{{picklist}}Selected value

Date fields

Salesforce field: Any Date type field (e.g., Account.BillingDate)

Format a date

Format date as DD/MM/YYYY
{{moment Account.BillingDate format="DD/MM/YYYY"}}

Expected output (if date is Feb 4, 2024):

04/02/2024

Common date formats

Different date formats
{{moment Account.BillingDate format="YYYY-MM-DD"}}

Expected output:

2024-02-04

Format with text

Date with readable format
Document date: {{moment Account.BillingDate format="MMMM DD, YYYY"}}

Expected output:

Document date: February 04, 2024

DateTime fields

Salesforce field: Any DateTime type field (e.g., Opportunity.CreatedDate)

Format datetime with time

DateTime with time
{{moment Opportunity.CreatedDate format="DD/MM/YYYY HH:mm"}}

Expected output:

04/02/2024 15:30

Format with readable text

Readable datetime
Created on {{moment Opportunity.CreatedDate format="MMMM DD, YYYY [at] hh:mm A"}}

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

Currency with symbol and formatting
{{currencyIcon "USD"}} {{number Opportunity.Amount "0,0.00" "en-US"}}

Expected output (if Amount = 15250.50):

$ 15,250.50

Dynamic currency from field

Currency from Salesforce field
{{currencyIcon Account.BillingCountry.CurrencyCode}} {{number Opportunity.Amount "0,0.00" "en-US"}}

Expected output:

€ 15,250.50

Currency with localization

European currency format
{{currencyIcon "EUR"}} {{number Opportunity.Amount "0,0.00" "de-DE"}}

Expected output:

€ 15.250,50
Localized number formats

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

Number with comma separators
{{number Account.NumberOfEmployees "0,0" "en-US"}}

Expected output (if value = 1500000):

1,500,000

Number with decimals

Number with 2 decimal places
{{number Product.ListPrice "0,0.00" "en-US"}}

Expected output (if value = 99.5):

99.50
Use number0 for safety

Use 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

Percent with decimal
{{number Opportunity.Probability "0.00"}}%

Expected output (if value = 85.5):

85.50%

No decimals

Whole percent
{{number Opportunity.Probability "0"}}%

Expected output:

85%

Checkbox fields

Salesforce field: Any Checkbox type field (e.g., Account.Active__c)

Show as checkmark/X

Checkbox as symbol
Status: {{showCB Account.Active__c}}

Expected output:

Status: ✓ (if checked) or Status: ✘ (if unchecked)

Show as yes/no text

Checkbox as conditional text
{{#if Account.Active__c}}Active{{else}}Inactive{{/if}}

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

Long text with line breaks
{{nl2br Account.Description format="PDF"}}

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
Important

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

Rich text for Word documents
{{docxHtml Account.RichTextDescription__c}}

With content validation

Rich text with content validation
{{#isTruthy Account.RichTextDescription__c}}
{{docxHtml Account.RichTextDescription__c}}
{{/isTruthy}}
Important notes
  • Case sensitive: Must use docxHtml (not docxhtml or other variations)
  • Content validation: The content cannot be null or blank. Always wrap with isTruthy to validate before passing to docxHtml
  • No embedded images: docxHtml does not support embedded images
  • Testing: Verify content formatting in actual Word documents before deploying to production
HTML to DOCX conversion

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

Email field
Contact: {{Contact.Email}}

Expected output:

Contact: john.smith@example.com
Email as clickable link
<a href="mailto:{{Contact.Email}}">Send email</a>

Expected output:

Send email (clickable link)

Phone fields

Salesforce field: Any Phone type field (e.g., Account.Phone)

Display as plain text

Phone field
Phone: {{Account.Phone}}

Expected output:

Phone: (555) 123-4567
Standardize phone format

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

Picklist field
Status: {{Opportunity.StageName}}

Expected output:

Status: Closed Won

Best practices

  1. Always test with real data — Test your formatting with actual Salesforce records to catch edge cases
  2. Handle null/empty values — Use {{#if}} to show alternative text for missing data
  3. Use the right helper — Match the helper to the field type (dates → moment, numbers → number, etc.)
  4. Localize numbers and dates — Use locale codes for international documents
  5. Format consistently — Keep formatting conventions the same across all templates
  6. Preserve special formatting — Use nl2br for long text and triple braces for rich text