Help Center Conditional Logic Conditional Formatting

Apply Conditional Formatting to Documents in Salesforce with Dochly

Updated June 2026 8 min read Conditional Logic
Conditional formatting changes how content looks — not just whether it appears. Highlight overdue invoices in red, bold the total row when a discount is applied, shade renewal rows in amber, or colour-code status labels based on their value. All driven automatically by Salesforce field data. This guide covers every formatting property available, how to apply them to rows, cells, and text, and a pattern library of ready-to-use formatting rules.

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.

Use conditional formatting when

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.

Use show/hide instead when

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

Change the text colour of the element when the condition is true. Use hex values (#dc2626 for red, #16a34a for green, #d97706 for amber) or standard named colours. Most commonly used to highlight statuses, flag negative values, or distinguish content types by colour.

Bold / font weight

Apply bold styling when the condition is true. Used for totals rows, high-priority items, or key values that should stand out. Can be combined with colour for maximum visual emphasis — e.g. bold red for critical overdue items.

Background colour

Fill the cell or paragraph background with a colour when the condition is true. Use light tints for table rows (#fff0f0 for light red, #f0fdf4 for light green, #fffbeb for light amber) — avoid saturated backgrounds that make text hard to read.

Border

Apply or change a border on the element when the condition is true. Useful for highlighting a specific row with a coloured left border — a common pattern for drawing attention without background colour. Specify border side, width, style, and colour.

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.

1

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.

2

Open Conditional Logic → Add Condition

In the right-hand properties panel, click Conditional LogicAdd Condition. Set the Field, Operator, and Value as you would for any condition — e.g. Days_Overdue__c > 30.

3

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.

4

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. #dc2626 for red
  • Bold: Toggle on to make the text bold when the condition is true
  • Background Colour: Enter hex — e.g. #fff0f0 for light red background
  • Border: Set side (left/all), width (1–3px), style (solid/dashed), colour
5

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 line items — conditional row formatting 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

Invoice / Financial

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.

Proposal / Quote

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.

Contract / Status report

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.

Financial report

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.

Project / Milestone

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.

Risk / Compliance

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

Use light background tints

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.

Keep colour semantics consistent

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.

Don't rely on colour alone

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.

Test in print/PDF preview

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

Yes. Row-level formatting conditions use the same field scope as row filter conditions — fields on the related list record. So you can format an entire row based on any field value on that row's related record. For example, apply a red background to the entire row when the row's Days_Overdue__c field is greater than 0 — the formatting evaluates the Days_Overdue__c value specific to each row as the table iterates.
Conditional formatting only applies when the condition is true — when false, the element retains its template-defined default styling (which may be no special formatting at all). You don't need to explicitly "reset" — the default state is whatever styling you applied to the element in the base template. If you want no formatting by default and formatting only when a condition is true, just leave the element with default styling and add a single formatting rule for the condition.
Rules are applied in the order they appear in the Conditional Logic panel — later rules override earlier ones for conflicting properties. For example, if Rule 1 sets colour to green and Rule 2 sets colour to red, and both conditions are true simultaneously, Rule 2 wins and the text is red. For mutually exclusive states (e.g. paid/overdue/critical), this conflict doesn't arise — only one rule can be true at a time. Reorder rules in the panel by dragging them if needed.

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.

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install