Subject, Body, and HTMLValue columns of Email Template are not correctly populated when Visualforce markup is modified
Trailblazer Community

Subject, Body, and HTMLValue columns of Email Template are not correctly populated when Visualforce markup is modified

Apex

Last updated 2019-09-04 ·Reference W-2580812 ·Reported By 21 users

No Fix

Summary
Upon creating a VF template, the SOQL on the template does not return Subject & Body field.

Repro
1. In any org,

Setup | Email | My Templates

Click New Template

2. Select 'Visualforce' as template type.
3. Fill all the required fields and click save.

Then run the following SOQL in Apex from either Developer Console or Workbench using the ID of the template created above:

SELECT Body,Subject FROM EmailTemplate WHERE Id = '00Xi0000000FTEh'

Both Body and Subject are returned as blank

Workaround
1. After modifying the markup of a Visualforce email template, either through the UI or metadata API, manually open the template , click on 'Edit Properties', and save the template. This should correct the problem.

2. Alternatively, if you intend to use the visualforce email template (?) in apex, you can query the 'TemplateType' field in the SOQL, to determine if the email is a Visualforce template, and retrieve the markup from the 'markup' field instead. Example: SELECT Subject, Body, HtmlValue, Markup, TemplateType FROM EmailTemplate

Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.