Skip to content
Home » News and articles » Visualforce Email Templates: Advantages and limitations

Visualforce Email Templates: Advantages and limitations

Recently I have been exploring Visualforce email templates in my Salesforce org and it’s a great pleasure to work with such an amazing feature! Visualforce templates offer powerful advantages over standard HTML and plain-text templates. They allow us to harness the full potential of Salesforce’s data manipulation capabilities, providing dynamic and personalised email content that can adapt to specific use cases like newsletters, automated emails, and more.

Despite the many advantages, we must also consider certain limitations, particularly when working with standard Visualforce pages and Apex classes. Some components we might be accustomed to using are not available in this context.

Advantages:

  • Dynamic Content: Use Visualforce to include conditional logic, custom loops, and dynamic data from Salesforce records, making emails more relevant and personalised.
  • Advanced Formatting: You can style templates with CSS or custom HTML, ensuring your emails are visually appealing.
  • Custom Attachments: Attach files dynamically (e.g., PDFs or HTML tables) using the tag, which can include specific Salesforce data.
  • Language Translation: Use the language attribute to automatically translate emails based on the recipient’s preferred language.
  • Interactive Data: Include interactive links to Salesforce records, helping recipients quickly access related information.
  • Highly Customizable: With custom controllers, you can design templates that pull unique datasets or perform advanced operations unavailable in standard templates.
  • Automation-Friendly: Integrate with Flows to send emails for specific triggers, such as case updates or marketing newsletters.
  • Brand Alignment: Tailor fonts, colors, and styles for email branding, using inline styles for consistent rendering across email clients.
  • Error-Free Data Retrieval: Use powerful merge fields and logic to ensure no blank or incorrect data is sent.
  • Professional Look: Visualforce templates can maintain a polished, professional aesthetic, suitable for customer-facing communications.

Best practises to remember:

  • Use Tags: Every Visualforce email template must be enclosed within a messaging:emailTemplate tag.
  • Choose Recipient & Related Record Types: Define the recipientType (e.g., Contact, Lead) and relatedToType (e.g., Account, Opportunity) attributes for context.
  • HTML vs. Plain Text: Use for HTML content or for plain text. Only one type can be included per template.
  • Avoid Prohibited Components: Components like apex:form, apex:pageBlock, and apex:detail are not supported in Visualforce email templates.
  • Character Limitations: The maximum size of a Visualforce email template is 1 MB.
  • CSS Compatibility: Include inline CSS styles directly in the style tag within the email body. Avoid relying on external stylesheets or static resources.
  • Test Across Email Clients: Email clients often render HTML differently, so test your template on popular clients (e.g., Gmail, Outlook) to ensure proper formatting.
  • Attachment Limitations: If adding attachments, ensure file sizes stay within limits (e.g., 60 MB for PDFs, 30 MB for images in PDFs).
  • No Mass Emails: Visualforce email templates are not compatible with mass email features. For bulk emails, use list email or other automation tools.
  • Custom Controller Access: If leveraging a custom controller, set its access to “global” for compatibility with the template.