Getting Error: Syntax error when i tried to add the below condition in Visual-force Email Template with dynamic variable

{!IF(recipient.RecordType.Name != 'Guardian',{!relatedTo.Name__c}, {!relatedTo.Name__c} )}

enter image description here

Can anyone help me what i am missing here


This statement alone will not work when visualforce is compiled but I am pretty sure you are simply trying to output a custom field on the relatedTo when the recipient does not match a certain Record Type. Quick tip, if your condition is producing the same output for both boolean expressions, a refactor is needed.

We can start first by making use of the apex:outputText attribute which gives us the ability to "render" a message/value based on a condition such as recipient.RecordType.Name != "Guardian".

<apex:outputText rendered="{!IF(recipient.RecordType.Name != "Guardian", true, false)}" value="{!relatedTo.Name}"/>

Note, when using relatedTo you will be asked to also define a relatedToType in your messaging:emailTemplate attribute of the visualforce email template. This is the SObject from which the template retrieves merge field data.

You may also place such render in an outer block such as a panel if you have an if-else flow.

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.