Apply Conditional Formatting to Documents in Salesforce with Dochly
What conditional formatting does
Conditional formatting applies visual styling to a document element — a row, cell, paragraph, or inline text — when a specified condition is true. The document content stays the same; only the visual presentation changes based on the data.
Unlike show/hide conditions which control presence, formatting conditions control appearance. An element with conditional formatting always appears in the document — but its colour, weight, or background adapts to the field value.
The content should always appear but its visual weight or colour should reflect its significance — overdue items in red, discounted lines in amber, completed milestones in green. The reader needs to scan quickly and formatting guides their attention to what matters.
The content should be completely absent in some documents — not just styled differently. If the goal is "this section should not exist for this customer", use show/hide. Conditional formatting is the wrong tool for visibility control.
Available formatting properties
Dochly supports four conditional formatting properties. Each can be applied independently or combined on the same element:
Font colour
Bold / font weight
Background colour
Border
How to apply conditional formatting
Conditional formatting is configured in the same Conditional Logic panel used for show/hide — but instead of setting the Action to "Show" or "Hide", you set it to "Apply Formatting" and then specify which formatting properties to change.
Select the element to format
Click the table row, cell, paragraph, or text run you want to format conditionally. For table rows, click anywhere in the row to select the entire row. For individual cells, click specifically in the cell.
Open Conditional Logic → Add Condition
In the right-hand properties panel, click Conditional Logic → Add Condition. Set the Field, Operator, and Value as you would for any condition — e.g. Days_Overdue__c > 30.
Set the Action to "Apply Formatting"
In the Action dropdown, select Apply Formatting when condition is true. A formatting sub-panel opens below — showing the four available properties: Font Colour, Bold, Background Colour, Border.
Configure the formatting properties
Enable the properties you want to change and set their values:
- Font Colour: Enter a hex code or pick from the colour picker — e.g.
#dc2626for red - Bold: Toggle on to make the text bold when the condition is true
- Background Colour: Enter hex — e.g.
#fff0f0for light red background - Border: Set side (left/all), width (1–3px), style (solid/dashed), colour
Preview against records with and without the condition
Save the template. Preview using a record where the condition is true (e.g. an invoice with overdue days > 30) and one where it's false. Confirm the formatting applies correctly in the true case and the element has its default styling in the false case.
Formatting entire table rows
Row-level formatting is the most common application of conditional formatting — changing the background or text colour of an entire row based on a field value. Here is an invoice table where rows are conditionally styled by payment status:
| Invoice # | Customer | Amount | Due Date | Status | Days Overdue |
|---|---|---|---|---|---|
| INV-0041 | Acme Corp | £5,200 | 01 Jun 2026 | ✓ Paid | — |
| INV-0042 | Beta Ltd | £1,800 | 15 Jun 2026 | Pending | — |
| INV-0043 | Gamma Inc | £3,400 | 01 May 2026 | ⚠ Overdue | 14 days |
| INV-0044 | Delta PLC | £8,750 | 01 Apr 2026 | ✗ Critical | 43 days |
// Three formatting rules on the same data row:
// Rule 1: Paid — green background
IF Payment_Status__c == "Paid"
APPLY background-color: #f0fdf4
// Rule 2: Overdue 1–30 days — amber background + bold
IF Days_Overdue__c > 0 AND Days_Overdue__c <= 30
APPLY background-color: #fffbeb; font-weight: bold
// Rule 3: Critical — overdue more than 30 days — red + bold
IF Days_Overdue__c > 30
APPLY background-color: #fff0f0; color: #dc2626; font-weight: bold
Multiple formatting rules can be applied to the same element — add them in sequence in the Conditional Logic panel. Dochly applies them in order, with later rules overriding earlier ones if they conflict. Keep rule order logical: most specific conditions last (so they take precedence over general rules).
Formatting individual cells
Cell-level formatting applies to a specific column within a row — without affecting the entire row. This is useful for status indicator cells, numeric value cells where positive/negative should be colour-coded, or any cell where the value's visual treatment should differ from the rest of the row.
// Cell formatting — colour-code a "Change" column in a financial table
// Applied to the cell in the "Change %" column of the data row:
IF Revenue_Change_Pct__c > 0
APPLY color: #16a34a; font-weight: bold // Green for growth
IF Revenue_Change_Pct__c < 0
APPLY color: #dc2626; font-weight: bold // Red for decline
// Zero change: no formatting rule = default black text
Cell formatting is configured by selecting the specific cell (not the whole row) in the template editor and adding conditions to it. The condition fields available for a cell in the data row are the same as for row conditions — fields on the related list record.
Formatting inline text
Conditional formatting can be applied to a run of text within a paragraph — not just to table elements. Select the specific text in the template editor, apply a condition, and set the formatting action. This is useful for contract paragraphs where specific values need to stand out.
// Example: bold and colour the total amount in a contract paragraph
// when it exceeds a threshold — drawing attention to large commitments
The total value of this agreement is {{if Amount >= 100000}}
[bold + colour #dc2626] {{Amount | currency}} [end formatting]
{{else}}
{{Amount | currency}}
{{/if}}, payable in accordance with the payment terms below.
For inline text formatting, the if/else approach (wrapping the merge field in a condition with different formatting on each branch) is more flexible than the visual condition builder. The true branch includes the formatted merge field; the else branch includes the same merge field without formatting.
Multi-state colour coding
Many use cases require more than two formatting states — not just "red if overdue" but "green if paid, amber if due soon, red if overdue, grey if cancelled". Apply multiple formatting rules to the same element, one per state.
// Four-state status formatting on a contract status cell
IF Contract_Status__c == "Active"
APPLY color: #16a34a; font-weight: bold
IF Contract_Status__c == "Pending Renewal"
APPLY color: #d97706; font-weight: bold
IF Contract_Status__c == "Expired"
APPLY color: #dc2626; font-weight: bold
IF Contract_Status__c == "Cancelled"
APPLY color: #94a3b8
// Each rule is a separate condition added to the element's Conditional Logic panel.
// Only one rule can be true at a time (mutually exclusive status values),
// so there is no conflict between rules.
Pattern library
Red row background for overdue invoices
Condition: Days_Overdue__c > 0 — Apply: background-colour #fff0f0, font colour #dc2626, bold. Instantly identifies overdue items in an account statement or invoice ageing report without the reader having to check dates manually.
Bold and amber the total row when a discount is applied
Condition: Discount_Pct__c > 0 — Apply to the totals row: font colour #d97706, bold. Draws the reader's eye to the discounted total. On standard-price quotes, the total row has default black styling.
Green/amber/red status cells based on contract health
Three rules on the status cell: Active → colour #16a34a bold; Pending Renewal → colour #d97706 bold; Expired → colour #dc2626 bold. A contract portfolio summary document becomes immediately scannable — no need to read every status value.
Colour-code positive/negative change percentages
Two rules on the "Change" cell: value > 0 → colour #16a34a bold; value < 0 → colour #dc2626 bold. Zero or blank: default styling. Revenue growth/decline columns in financial summaries become instantly readable.
Green background for completed milestones
Condition: Milestone_Status__c == "Complete" — Apply: background-colour #f0fdf4. Milestone rows that are incomplete have white background. A project status document shows progress at a glance — completed milestones visually pop from incomplete ones.
Red left border on high-risk items
Condition: Risk_Level__c == "High" — Apply: left border 3px solid #dc2626. A subtle but effective highlight — high-risk items have a red left border stripe; all other rows have no border. Less visually aggressive than a full red background but still clearly draws attention.
Best practices
For row backgrounds, use very light tints — #fff0f0 not #dc2626 for red rows. Dark backgrounds make body text unreadable. Aim for backgrounds that are clearly tinted but still easy to read over.
Use colour consistently across the document: green = positive/complete, amber = attention/pending, red = critical/overdue, grey = inactive/cancelled. Inconsistent colour semantics confuse readers and undermine the visual communication.
Combine colour with a text label or icon — "✓ Paid" in green is better than just a green cell with "Paid". Some readers have colour vision deficiency — text reinforces the visual signal for all readers.
Conditional formatting should be tested in actual PDF output — colours render slightly differently in print than on screen. Verify backgrounds don't wash out and text remains readable at all the colour states. Always preview in PDF mode before setting Active.
Frequently asked questions
Conditional formatting now makes your documents visually intelligent. Next in this series: Use conditional logic with related lists in Dochly — filter, group, and control related list content using conditions on child record fields.
Rated 5 stars · Native Salesforce app · Free to install