You need to sign in to do that
Don't have an account?

VisualForce Email Template as part of a WorkFlow- merge fields not populating
Hi Community,
I have the below VisualForce Email Template:
The issue is that the Email notification doesn't populate the Merge Fields:

Below is my email client's 'original' massage:

Thank you
I have the below VisualForce Email Template:
<messaging:emailTemplate subject="[Email] #{!relatedTo.CaseNumber} - {!relatedTo.Subject} - {!relatedTo.Contact.Name}" recipientType="User" relatedToType="Case"> <messaging:htmlEmailBody > <html> <style type="text/css"> body {font-family: arial; size: 12pt;} </style> <body> <img src="https://my.salesforce.com/servlet/servlet.ImageServer?id=01561000001JYOm&oid=OBFUDCATED"/><br/> A <b>new Email</b> was added to the case below: <br />------------------------ <br />• Case #: {!relatedTo.CaseNumber} <br />• Account: <apex:outputLink value="https://my.salesforce.com/{!relatedTo.Account}">{!relatedTo.Account.Name}</apex:outputLink> <br />• Contact Name: <apex:outputLink value="https://my.salesforce.com/{!relatedTo.Contact}">{!relatedTo.Contact.Name}</apex:outputLink> <br />• Case status: {!relatedTo.Status} <br />• Priority: {!relatedTo.Priority}<apex:image id="theImage" value="{!relatedTo.Priority_Flags_URL__c}" width="12" height="12"/> <br />• Link: https://my.salesforce.com/{!relatedTo.Id} <apex:outputPanel rendered="{!relatedTo.Jira__c!=null}" > <br />• Jira issue: <apex:outputLink value="https://www.atlassian.net/browse/{!relatedTo.Jira__c}">{!relatedTo.Jira__c}</apex:outputLink></apex:outputPanel> <apex:outputPanel rendered="{!relatedTo.Git_Link__c!=null}" > <br />• Git Link: <apex:outputLink value="{!relatedTo.Git_Link__c}">{!relatedTo.Git_Link__c}</apex:outputLink></apex:outputPanel> <br />------------------------ <apex:outputPanel rendered="{!relatedTo.Last_Incoming_Email_Content__c!=null}" style="white-space:pre;"> <h3><br /><b><u>Case Last Incoming Email:</u></b></h3><br /> <apex:outputField value="{!relatedTo.Last_Incoming_Email_Content__c}" style="white-space:pre;"></apex:outputField> </apex:outputPanel> </body> </html> </messaging:htmlEmailBody> </messaging:emailTemplate>This VF Email is used in a WorkFlow rule, to send and Email Alert for each new incoming Email to the case which is under his custody. The WorkFlow Rule is pretty simple, it 'listens' to the change in the Custom Field 'Last_Incoming_Email_Content__c', and fires the email notification.
The issue is that the Email notification doesn't populate the Merge Fields:
Below is my email client's 'original' massage:
Date: Mon, 31 Oct 2016 12:13:08 +0000 (GMT) From: System <obfuscated> Sender: noreply@salesforce.com To: "obfuscated" <obfuscated> Message-ID: <QLFAw000000000000000000000000000000000000000000000OFWV9W004MUKYztRQrCfzfyDk0URBQ@sfdc.net> Subject: [Email] #00008640 - - MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_16014_1675508803.1477915988038" X-SFDC-LK: 00D61000000edsH X-SFDC-User: 00561000001nhq1 X-Sender: postmaster@salesforce.com X-mail_abuse_inquiries: http://www.salesforce.com/company/abuse.jsp X-SFDC-TLS-NoRelay: 1 X-SFDC-Binding: 1WrIRBV94myi25uB X-SFDC-EmailCategory: workflowActionAlert X-SFDC-EntityId: obfuscated X-SFDC-Interface: internal ------=_Part_16014_1675508803.1477915988038 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ------=_Part_16014_1675508803.1477915988038 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <html> <style type="text/css"> <!-- body {font-family: arial; size: 12pt;} //--> </style>In addition, when testing with the 'test and verify merge fiels' in the Email Template editor, everything looks fine:
Thank you
Also you should avoid hardcoding salesforce URL's in email templates as it changes in Sandbox instances. The above solution should work in all of your environments.
Mark it as Best Answer if it helps.
I will avoid hardcoding links to allow sandbox support.
In regards the original issue - I changed the links and they had no affect. Issue presist, as the Email Message still doesn't populate the merge fields.
Account: <a href="https://*.salesforce.com/"></a>
Below is the full 'original' message from my Email Client (Gmail):
I changed the recipientType="Contact" and tested, with same results.
If yes, you might have to set debug logs before sending email and see whats happening.
The test case has an associated account, and contact. These Merge Fields appear properly when using the 'test and verify merge fiels' in the VisualForce Email Editor. Furthermore, there are other Merge Fields which are not populating in the Email Client, such as my custom 'Last_Incoming_Email_Content__c'.
The interesting thing is that some Merge Fields do work. The CaseNumber is a goo eample for a Merge Files which populated in the HTML body, but wasn't able to populate in the Email Subject.
I turned on the finest debugging using Debug Logs, and captured the logs:
Unfurtunately, the logs doesn't seem to have enough information to further debug this.
I tried the same template in my developer org and it seems its working for me
VF Template-
Workflow Rule-
Workflow Rule Detail
Rule Name test Object Case
Evaluation Criteria Evaluate the rule when a record is created, and every time it's edited
Active
Description
Rule Criteria Case: StatusNOT EQUAL TO null
Email Alert:-
Email Alert Detail
Description Send email to user Protected Component
Unique Name Send_email_to_user
Email Template Case Email Template
Object Case
From Email Address Current User's email address
Recipients User: Lakshman
Additional Emails
The email which I got with all fields merge-
A new Email was added to the case below:
------------------------
• Case #: 00001024
• Account: United Oil & Gas Corp.
• Contact Name: Lauren Boyle
• Case status: Working
• Priority: Low
• Link: https://my-dev-ed.my.salesforce.com/50090000001M6mXAAS
Can you check this same example in your org with the same setup ? I think something is missing or preventing to get the fields merge on your side.
Possible solution-
Create a component and reference it in VF template, sample example- https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm
But I am sure that the template should work and we may not be needing to create the component and controller.
I took the exact VF Email Template from your example, and received the same result - the Email came in as follows (no Account, Contact Name or Priority):
------------------------
• Case #: 00007332
• Account:
• Contact Name:
• Case status: In Progress
• Priority:
• Link: https://cs61.my.salesforce.com/5004C000000usL2QAI
I followed the link to the Developers Guide 'Using Custom Controllers within Visualforce Email Templates (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm)', and noted the footnote about sharing:
For information about sharing for the user object, see User Sharing Overview in the Salesforce online help."
I set the Case and Account records to be publicly visible under 'organization-wide default', and retested. Again, same results, so this doesn't seem to be the cause.
I tested again, and changed my current WorkFlow Rule Criteria which was:
ISCHANGED(Status)
After this change, the Email arrived with the populated Merge Fields.
I believe there's sort of a rece condition with my Custom Field 'Last_Incoming_Email_Content__c' which is causing this, but am not sure why.
This custom field is being updated in the scope of a different WorkFlow Rule, which simply copy the Case Email Message body to this custom field, through the below Formula (on a 'Field Update' inside the WorkFlow Rule):
IF(HtmlBody<>"", HtmlBody, TextBody)
I'm looking online to find similar 'WorkFlow Race Condition' topics, with no luck so far.