[SalesForce] How to create IF Statements in Visualforce email template

Hi I have create the Visualforce email template and i have attach the pdf file,in that pdf file name has been Certificate .pdf, but the file name a particular parent name Eg: Mecca Bingo it will show email out upon the pdf file name merging the Four filed name.

I have create the IF statement in email template but it has been show the error.

<messaging:attachment filename="{!relatedTo.Site__r.AM_UPRN__c}-
{!relatedTo.Site__r.ShippingCity}-{!relatedTo.Visit__r.Service_Type__c}-{!relatedTo.Date__c}" 
renderAs="pdf"> 

this is my merged file name but i have tried for if statement

<messaging:attachment filename="{!If(relatedTo.Site__r.Name='Mecca Bingo',
relatedTo.Site__r.AM_UPRN__c,'Certificate.pdf')}" renderAs="pdf"> 

It was working nice but i need check the second one merged fields check the if statement i have tried it was occure the error

{!relatedTo.Site__r.AM_UPRN__c}-
{!relatedTo.Site__r.ShippingCity}-{!relatedTo.Visit__r.Service_Type__c}-{!relatedTo.Date__c}

But I need to check in this format to IF statement

<messaging:attachment filename="{!If(relatedTo.Site__r.Name='Mecca Bingo',
({!relatedTo.Site__r.AM_UPRN__c}-
{!relatedTo.Site__r.ShippingCity}-
{!relatedTo.Visit__r.Service_Type__c}-
{!relatedTo.Date__c}),'Certificate.pdf')}" renderAs="pdf">

Please anyone kow let me know…

Thanks in advance 🙂

Best Answer

Try this:

<messaging:attachment filename="{!If(relatedTo.Site__r.Name='Mecca Bingo',
(relatedTo.Site__r.AM_UPRN__c-
relatedTo.Site__r.ShippingCity-
relatedTo.Visit__r.Service_Type__c-
relatedTo.Date__c),'Certificate.pdf')}" renderAs="pdf">
Related Topic