I've never had any problems with standard, non-conditional merge fields, but I can't for the life of me figure out how to insert a working if...then formula into my Mail Merge documents.

I am basically just trying to generate different phrasing depending on true or false values related to (mostly custom)contact and opportunity fields. For example, if I want to create a letter to acknowledge both anonymous and public donors, I will insert the custom field that determines whether a contact is anonymous or not into the IF field:

"Thank you for your { IF { MERGEFIELD Contact_custom_field } = "Anonymous" "anonymous " ""} donation of ..."

But when I test the template, Salesforce always defaults to the false text instead of actually reading the formula and determining based on the merge fields I included.

I get the same results when I try greater than/less or equal/etc. formulas:

"The fair market value of your blahblah is { IF { MERGEFIELD Opportunity_Amount } >= 2000 "$500.00" "$250.00" }" will become "Your FMV is $250.00" every time, regardless of the merge field's actual recorded value.

This turned into a very long post, but if you've made it this far and have any answers I'd be grateful. Is it me? Is it Salesforce? It's driving me crazy.


Wrap the conditional merge field in quotes, e.g., { IF "{ MERGEFIELD Contact_custom_field }" = "Anonymous" "anonymous " ""}.

I've managed to set up a complex merge document with 20+ IF statements that successfully generates a nicely formatted 20 page Word doc that includes/excludes entire sections based on them.

The issue I am now grappling with is that IF statements are output as fields in the generated document (vs the simple mergefields which are converted to a text value as expected). This is particularly problematic where the ELSE output is blank ("") since it leaves the whole section in the document (though, to be fair, at least it is somewhat hidden behind an empty paragraph mark).

I can then either protect the form so no one can toggle to view the field codes or convert the Word doc to a PDF. My preference is to have a 'clean' merge document from the start so that I don't have extra steps to perform.

| improve this answer | |

Yes this is possible to have conditional IF statements in an email template. Some time its not works when you are using "HTML Email Template" because of metadata issue. Issue: If you are using IF statements in HTML email template, some time its metadat in backend add some formating html and css inside of IF statements, Thats why its not working.

Solution: Edit the email template matadata and remove all html and css which is inside of IF statement:

enter image description here

After removing all these strange and useless html, Save it. Now this will work for you :)

| improve this answer | |

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.