Use If/Else in Lightning Email Templates to Show Account Rating

Quick tip: Lightning Email Templates support limited conditional content — you can show fields like a parent Account’s Rating only when that parent exists. This post explains the approach, example, and best practices.

Overview

Salesforce Lightning Email Templates allow you to include dynamic merge fields and, in some cases, conditional logic to render content only when certain data exists. A common use case is showing the parent Account’s Rating inside an email only when a parent Account is present. While Lightning templates don’t expose full scripting, you can often achieve this “if/else” behavior using conditional merge expressions or template conditional blocks.

When to use conditional content in email templates

Use conditional content to personalize emails and avoid showing empty or irrelevant fields. Examples include:

  • Displaying Parent Account Rating only when Parent Account exists
  • Showing alternate text or links when a field is blank
  • Hiding sections of the template for certain record types or statuses

Example (high-level)

Conceptually you want: “If Parent Account exists → show Parent.Rating; otherwise → show nothing or an alternative message.” Exact syntax depends on the available merge/conditional features in your Salesforce org and template type.

// Example (pseudo merge expression)
{!IF(Account.ParentId != null, Account.Parent.Rating, '')}

Note: The line above is a conceptual example; Lightning Email Template editors may provide a conditional content block or a slightly different merge syntax. Refer to your org’s template editor or Trailblazer posts for precise syntax.

Best practices

  • Preview templates with records that have and don’t have the parent relationship to confirm rendering.
  • Use fallback text so recipients never see empty placeholders.
  • Keep conditional logic simple — complex conditions are better handled in formula fields or using automation to populate helper fields.
  • Document the merge fields and any assumptions so business users can maintain templates safely.

Reference: Trailblazer post showing a similar pattern — see community posts and the Lightning template editor documentation for the exact available syntax and conditional block support.

Why this matters

Personalized, conditional content reduces confusion and increases engagement by only showing relevant data. For Salesforce admins and developers, using conditional content in Lightning Email Templates is a lightweight way to improve communication without adding heavy automation. When conditional logic becomes complex, consider pre-calculating values with formula fields, flows, or Apex before rendering them in the template.

Categories: Salesforce Tips