+ Start a Discussion
SeanGormanSeanGorman 

Escaping characters in VisualForce Email

THis is a repeat post but I cannot find any way of getting this done:

 

I have a VF email template.

 

<messaging:emailTemplate subject="Account Training Review Required" recipientType="User" relatedToType="Case">
<messaging:HTMLEmailBody >
<html>

----

{!if(relatedTo.Education_checkbox__c = true, " as identified by the Product Support case owner.", " as indicated by a relatively high percentage of support calls having been resolved as 'how to' questions.")}

 The above is what I want... But try that and you get this error:

	Error: EL Expression Unbalanced: ... #{if(relatedTo.Education_checkbox__c = true, " as identified by the Product Support case owner.", " as indicated by a relatively high percentage of support calls having been resolved as 'how to' questions.")} This client’s particular profile#{if(relatedTo.Account.Business_Size__c = "BB", ", an account classified as Big Business,", if(relatedTo.Account.Business_Size__c = "SMB", ", an account classified as Small Business,", if(relatedTo.Account.Business_Size__c = "MB", ", an account classified as Mid-Size Business, ", "")))} has submitted #{if(text(floor(relatedTo.Account.AccountCases__c)) != "", text(FLOOR(relatedTo.Account.AccountCases__c)) & " how to cases in the last 90 days ", "no other cases categorised as how-to")} #{if(text(relatedTo.Account.Account_Cases_last_90_days__c) != "", " out of a total of " & TEXT(relatedTo.Account.Account_Cases_last_90_days__c) & " Product Support calls", "")}, which puts it in the #{relatedTo.AccountTrainingStatusCode__c} zone according to calculated metrics #{if(relatedTo.Account.MinCaseThreshold__c="Red", if(relatedTo.AccountTrainingStatusCode__c = "Red", " and " & relatedTo.Account.MinCaseThreshold__c & " when measured against the number of how to cases that we allow.", " but " & relatedTo.Account.MinCaseThreshold__c & " when measured against the number of how to cases that we allow."),".")}

 

If you try this: \'how to\' then you can save but the same thing is displayed in the email:

\'how to\'

 

Surround the text in the condition with htmlencode() and you see this in the email:

\&#39;how to\&#39;

 

Use jsencode() and you see this:

\\\'how to\\\'

 

Clearly the system wants me to escape the character but it then doesn't do anything about it.

 

Please can someone help?

Best Answer chosen by Admin (Salesforce Developers) 
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

To overcome this escape characters to be printed in you email, you need to give the ASCII value for comma before and after how to

 

Try the following,

 

{!if(relatedTo.Education_checkbox__c = true, " as identified by the Product Support case owner.", " as indicated by a relatively high percentage of support calls having been resolved as &#44;how to&#44; questions.")}

 

For your refference about ascii characters, see the below link,

http://www.ascii.cl/htmlcodes.htm

 

In the above example i used &#44; because that is the ascii charater for comma.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

All Answers

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

To overcome this escape characters to be printed in you email, you need to give the ASCII value for comma before and after how to

 

Try the following,

 

{!if(relatedTo.Education_checkbox__c = true, " as identified by the Product Support case owner.", " as indicated by a relatively high percentage of support calls having been resolved as &#44;how to&#44; questions.")}

 

For your refference about ascii characters, see the below link,

http://www.ascii.cl/htmlcodes.htm

 

In the above example i used &#44; because that is the ascii charater for comma.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

This was selected as the best answer
SeanGormanSeanGorman

Just so anyone see this in the future: if you want double quotes to delimit a phrase in a VF Email condition the it is easy to use \"my phrase here\".

 

But if you want to do it correctly and use a single quote then use the solution of this post by : &#39;

 

Why the difference? I do not know.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

The difference is because you are using this as a html format email template.

 

In HTML  markup language, by defult if you wrinting a text then, you need to write the special characters as ascii only.

For that purspose we have ascii formats.