[SalesForce] creating Mail Merge templates with if fields

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.

Best Answer

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.

Related Topic