+ Start a Discussion
Peter Yao 9Peter Yao 9 

Can't query HtmlValue for deleted EmailTemplates in Summer 18

We have deleted email templates and a SOQL query that includes HtmlValue or Body works differently in Summer 18 than Spring 18.

Specifically, doing this in an Anonymous Apex window in Summer 18:
List<EmailTemplate> templates = [SELECT Id, HtmlValue FROM EmailTemplate];
Results in an "Internal Salesforce.com Error".

Running that SOQL in the Query Editor raises a dialog "entity is deleted".

Apex tests that have that SOQL fail with an Internal Salesforce.com Error.

It works fine if I omit HtmlValue, include a where clause that excludes deleted templates, or if I run it in a Spring 18 org.

I don't see a known issue about it - is it an issue for others? Is there a way to exclude all deleted templates in SOQL?

Kai Herng LauKai Herng Lau
Hi Peter,

I'm using developer console to execute the query and I have no problem about this. Do you have the some problem on developer console? If yes, can you do some troubleshooting to find out if it is because of certain value in the 'HtmlValue' that causing the problem?

Another tips the HtmlValue is the rich text field if you put it in the where clause you will hit into cannot filter error.

Please let me know of your finding? thanks
Peter Yao 9Peter Yao 9
Hmm - that's good to know. Do you have EmailTemplates that are deleted?

When my query returns a deleted EmailTemplate, the HtmlValue is null in a Spring 18 org, but I get an Internal Salesforce.com Error in a Summer 18 org. The EmailTemplate is deleted, so there's no way to see what's in the HtmlValue. The same behavior is there if I select Body instead of HtmlValue.
Kai Herng LauKai Herng Lau
Hi Peter,

I have one emailTemplate is deleted but it is not appear in my query. May I know how do you get the deleted record exist in your query?