OK, I'm going to leave this page here, but lesson learned. After all this debugging it was NOT a technical issue it was a process issue. Well, the debugging allowed me to work out that it was NOT a technical issue, so go back to the very basics. Draw out the steps on paper. My process was doing this:
Then there was another workflow
So, what was happening?
So lessons learned:
|
I don't know if I will find an answer to this, but I am having a mysterious problem with visualforce emails not populating with data when being sent via a workflow, but they do send fine when sent via the Send Test and Verify Merge Fields button.
<messaging:emailTemplate subject="My Email Subject" recipientType="Contact" relatedToType="ObjectB__c" rendered="true">
Steps to try to work out what the problem is and fix it
Step | Notes | Result |
---|---|---|
Create formula fields for data | rather than {!relatedTo.ObjectA__r.Campaign__r.Account__r.Notes__c} I added the Notes field to Object B as a formula field so it was {!relatedTo.Notes__c} I did this for 3 fields | ![]() |
Send email immediately | The workflow was running after an hour | ![]() |
Simplified the HTML Email | ![]() | |
Added the IDs for all the objects into the email body | ![]() | |
Added the Names | If the Standard Fields of IDs display, do the standard fields of Names display? Because the field that is displaying from ObjectC is the Name field. | ![]() |
Added the new fields without any HTML embellishment | Just replaced the name fields that did display with the fields I wanted to display. | ![]() |
Wrapped the fields in the output tags | To try to see if there was anything to the non-answer in article 4. above. I also added Created Dates (standard fields) in output tags. |
|
Changed to plaintextemailbody | ![]() | |
Changed the Contact lookup to be directly from Custom Object B | So instead of {!relatedTo.ObjectA__r.Contact.Notes__c} I had {!relatedTo.Contact__r.Notes__c} | ![]() |
Send via process builder | Hey, it's worth a shot! But of course, since it just uses the standard email alert, it won't do anything different. | ![]() |
Sent the email from another object | I used a workflow to update ObjectA then send the email from there - it did not work even though there are other emails sending from that object quite fine. | ![]() |
Dialed back the API version | So, what was the difference between the email that was working and the one that was not? The API Version. The working email was on 32, the non working was on 33 | ![]() |
So, at this stage we know, it's not about the data model and it's not about HTML visualforce. It's not about the HTML structure and it's not about whether the fields are enclosed in output tags or not. It is only about whether the fields are custom fields or not.
I could test with another object but I need to send from this object.
I could test without visualforce emails but I need to use visualforce emails to have conditional text in this email.
Aha! Found it! See notes at the top! Stupid stupid me!