You need to sign in to do that
Don't have an account?

Dynamic Subject in visualforce email template based on value of field
Hi all,
I have a requirement in visualforce Email template. I need to conditionally display subject for Email templates based on a field value. I found the below one in some blog.
<messaging:emailTemplate subject="{!IF(relatedTo.LeadSource = 'Web','This is PG1 subject', IF(relatedTo.LeadSource = 'Other','This is PG2 subject','false') )}" recipientType="Lead" relatedToType="Lead">
<messaging:plainTextEmailBody>
{!
IF(relatedTo.LeadSource = "Web","This is PG1 email"
,
IF(relatedTo.LeadSource = "Other","This is PG2 email ","false")
)
}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
But in the subject i want to display Leasd source as well. Subject would be like "This is PG1 Email Web"/"This is PG1 Email Other".
Please help me with this requirement.
Thanks.
I have a requirement in visualforce Email template. I need to conditionally display subject for Email templates based on a field value. I found the below one in some blog.
<messaging:emailTemplate subject="{!IF(relatedTo.LeadSource = 'Web','This is PG1 subject', IF(relatedTo.LeadSource = 'Other','This is PG2 subject','false') )}" recipientType="Lead" relatedToType="Lead">
<messaging:plainTextEmailBody>
{!
IF(relatedTo.LeadSource = "Web","This is PG1 email"
,
IF(relatedTo.LeadSource = "Other","This is PG2 email ","false")
)
}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
But in the subject i want to display Leasd source as well. Subject would be like "This is PG1 Email Web"/"This is PG1 Email Other".
Please help me with this requirement.
Thanks.
All Answers
Mark as best answer, If it resloves
You need to design custom controller class where you can store lead source and required fields and form that controller you can call in visualforce page or Lightning component.
check below link for lightning component example
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm
Thanks,
Bhanu Prakash
visit ForceLearn.com (https://www.forcelearn.com)
Thanks for your reply. I tried this but not working.
Thanks.
I have tried the below code and it's working.
{!IF(relatedTo.LeadSource = 'Web','This is PG1 email'+relatedTo.LeadSource,IF(relatedTo.LeadSource = 'Other','This is PG2 email'+relatedTo.LeadSource,'false))}
But it is displaying the subject as This is PG1 emailWeb. There is no space between email and Web. I am still trying to apply different methods for this.
Thanks.
mark answers as best answer if it helps you
add space after email word.
I could not have posted here if just adding space after the word email works. I tried that before posting here.
Thanks.
Thanks a lot GhanshyamChoudhari. Marked your answer as best.