There have been ways in the past you could use (hack) custom formula's within Classic Email Templates to render content depending on the scenario. For example, you can use this formula directly in the email template -

{!IF(Custom_Field__c = 'something', 'Show something which means
success', 'Else show this part')}.

As of Spring '20 Release, Salesforce has put in a validation check to stop the user from inserting malformed Merge Fields (ref Release Notes). What's more is that the error doesnt show up when you are in 'Edit HTML version' mode (stays in Edit mode, does not save, no errors displayed).

PS - This doesnt affect existing templates (the formulas there will still work). But you can no longer edit them or create new ones with Formulas.

  • 1
    N.B. you don't need the == in the formula, = suffices. == is used in apex – cropredy Mar 25 '20 at 5:12
  • @cropredy Noted and updated. Thanks! – gutsyfella Mar 26 '20 at 16:52

Solution - It is normal for Admins/Devs to click the 'Copy from HTML' button on the Text version page while creating the Template. Therefore, your custom formulas will be copied over as well and you'll observe that you're unable to edit/save the template containing these as part of the Spring '20 update.

You need to remove the custom formulas (SF treats it as malformed merge fields now - see Release Notes) in the Text version.

You will be unable to save the Email Template if the custom formula exists in the Text Version of the template. The error will be visible when you try to 'Edit Text version'. This is the error you will get -

Error: A parsing error occurred saving the template: Syntax error. Missing ". Please make sure all merge fields are correctly formatted.

Issue Reference - https://success.salesforce.com/issues_view?id=a1p3A000000KRL6QAO

Release Notes - https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_sales_productivity_email_templates_malformed.htm

Since SF has not mentioned it in their Known Issue - see Ref (probably because they don't support/have no documentation on supporting Custom Formulas in Email templates), I had to spend some time debugging this. I personally don't use the Text version, so removed it altogether. Thereafter, I was able to edit/save the HTML version. Hope this helps people who are blocked on saving emails templates which use custom formulas.

Edit 1 - Upon further investigation I found that some of my Custom templates were completely locked out - There was no way of editing them at all (please see point 2 below). Upon following up with Salesforce Premier+ support, I was informed that their Product Team is aware about it but they had no workaround or fix date for this. There are 2 ways at the moment -

  1. For HTML templates - After deleting the content of the Text version and saving, I moved over to the HTML template. I cut-copied the entire text of the HTML template into an editor (so that no content remains in the HTML template). Clicked Save (to see if there are no merge template errors, since there is actually no content in the HTML template, it should save - I didnt get any merge syntax errors in my case). Then I copied in and saved para-by-para to troubleshoot the issue. I found this worked for me when I copied over from a text (notepad)/other editor (VS Code).
  2. For Custom templates - The answer that I gave above (removing the Text version first and then saving) worked for almost all of my Custom templates. For some of my custom templates, even after removing the entire content in the Custom Template and saving, SF still gave me a merge error! (This should technically not be possible because there is no content so there cannot be a merge error?) - I suppose for those specific custom templates, creating a new template at this point of time is the only way to go about it - unless someone else has other suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.