Can I get the merged email template in Apex without sending it? I'd like to inspect the generated email first.
I think I found the answer on https://salesforce.stackexchange.com/a/8745/2330
Can I get the merged email template in Apex without sending it? I'd like to inspect the generated email first.
I think I found the answer on https://salesforce.stackexchange.com/a/8745/2330
Yes you can. Here's an example with pictures explaining the process: Reference Link
Note: Just make sure the checkbox "Send Email to Preview" is not selected.
Testing Email Templates and Verifying Merge Fields
The easiest way to test the content and merge fields in your email templates is to simulate the conditions under which they are sent from the public site using a test account. That'll absolutely show you what happens. Salesforce does provide a way to test from the email template interface -- but it can be a little tricky. Here's what you need to know. When viewing the detail page of an email template, click on the "Send Test and Verify Merge Fields" button
When viewing the detail page of an email template, click on the "Send Test and Verify Merge Fields" button
Before doing so however, take a look at the merge fields that are being used in the template. Think about what workflow is triggering the email alert, and what object that workflow is build around. Let's try testing the email template "Notification of Volunteer Removals" Before clicking on the button -- consider what triggers this email. It is sent when an update is made to the Connection Record. The update is made by a contact in the system (the volunteer who has removed themselves). To properly test this - you need to find a connection record (and its contact), where this would have taken place. Otherwise there won't be proper data to merge.
What you see when you click on the "Send Test and Verify Merge Fields" button
What you see when you click on the "Send Test and Verify Merge Fields" button You are asked for 3 things here:
1) Who would be receiving the email. In this case, that would be the Opportunity Coordinator responsible for the opportunity the volunteer has just removed themselves from. So look up THEIR contact record.
2) Related to Record: This is what confuses most people. You don't want to look up an organization here. Instead you need to drop down the picklist and select a record of type "Connection". This should be a connection in your data where someone is in status removed.
3) If you want to receive the actual email (in addition to the preview you'll see on screen), Click the 'send email preview to" button and put in your email address.
Here's the correct info for me to send a test that will fill in all the merge fields!
When I click OK, I see an html preview appear:
Notice, all the merge fields are filled in. I'll also receive an email version of it if desired. Note: There are a few email templates where several objects are involved in producing all the necessary merge fields. These aren't controlled by workflows, but are triggered by apex triggers. For these, the only way to test that all merge fields from a range of objects will work - is to simulate the conditions of the email from the public site. (That's because you can't pull info from two different objects via the native salesforce "Send Test and Verify Merge Fields".