function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alimali Stephen 15Alimali Stephen 15 

IF Condition on Visualforce Email Template

Hello Team!
I want to add IF condition where if a certain picklist value is selected then a certain image is picked  through static resource image link.
The image picked should show in the vf email template as per the condition set.
 
<messaging:emailTemplate subject="Delivery Status for Invoice Number: {!relatedto.Number__c}" recipientType="Contact" relatedToType="Invoice__c">
<messaging:htmlEmailBody >
<apex:outputPanel >
<img src="my static resource image url" alt="" style="display: block; padding: 0px; text-align: center; height: 100%; width: 100%; border: 0px none transparent;" width="636">
</img>
</apex:outputpanel>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

The shared code is what I have so far on having the image to display but I am stuck in adding the IF condition to display different images as per a selected picklist value.

I'd appreciate any assistance on this.
Best Answer chosen by Alimali Stephen 15
Maharajan CMaharajan C
Hi Stephen,

Please try any one of the below way:

1. Use the rendered="{!ISPICKVAL(relatedTo.PickList_field__c ,'Your Picklist Value')}"
<messaging:emailTemplate subject="Delivery Status for Invoice Number: {!relatedto.Number__c}" recipientType="Contact" relatedToType="Invoice__c">
<messaging:htmlEmailBody >
<apex:outputPanel rendered="{!ISPICKVAL(relatedTo.PickList_field__c ,'Your Picklist Value')}">
<img src="my static resource image url" alt="" style="display: block; padding: 0px; text-align: center; height: 100%; width: 100%; border: 0px none transparent;" width="636">
</img>
</apex:outputpanel>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

2. Use the rendered="{!If(relatedTo.PickList_field__c == 'Your Picklist Value',true,false)}"
<messaging:emailTemplate subject="Delivery Status for Invoice Number: {!relatedto.Number__c}" recipientType="Contact" relatedToType="Invoice__c">
<messaging:htmlEmailBody >
<apex:outputPanel rendered="{!If(relatedTo.PickList_field__c == 'Your Picklist Value',true,false)}">
<img src="my static resource image url" alt="" style="display: block; padding: 0px; text-align: center; height: 100%; width: 100%; border: 0px none transparent;" width="636">
</img>
</apex:outputpanel>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

https://salesforce.stackexchange.com/questions/244376/visualforce-conditionally-render-2-different-fields-based-on-2-conditions

https://salesforce.stackexchange.com/questions/216995/conditional-rendering-using-if-in-visualforce-template


Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi Stephen,

Please try any one of the below way:

1. Use the rendered="{!ISPICKVAL(relatedTo.PickList_field__c ,'Your Picklist Value')}"
<messaging:emailTemplate subject="Delivery Status for Invoice Number: {!relatedto.Number__c}" recipientType="Contact" relatedToType="Invoice__c">
<messaging:htmlEmailBody >
<apex:outputPanel rendered="{!ISPICKVAL(relatedTo.PickList_field__c ,'Your Picklist Value')}">
<img src="my static resource image url" alt="" style="display: block; padding: 0px; text-align: center; height: 100%; width: 100%; border: 0px none transparent;" width="636">
</img>
</apex:outputpanel>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

2. Use the rendered="{!If(relatedTo.PickList_field__c == 'Your Picklist Value',true,false)}"
<messaging:emailTemplate subject="Delivery Status for Invoice Number: {!relatedto.Number__c}" recipientType="Contact" relatedToType="Invoice__c">
<messaging:htmlEmailBody >
<apex:outputPanel rendered="{!If(relatedTo.PickList_field__c == 'Your Picklist Value',true,false)}">
<img src="my static resource image url" alt="" style="display: block; padding: 0px; text-align: center; height: 100%; width: 100%; border: 0px none transparent;" width="636">
</img>
</apex:outputpanel>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

https://salesforce.stackexchange.com/questions/244376/visualforce-conditionally-render-2-different-fields-based-on-2-conditions

https://salesforce.stackexchange.com/questions/216995/conditional-rendering-using-if-in-visualforce-template


Thanks,
Maharajan.C
This was selected as the best answer
Alimali Stephen 15Alimali Stephen 15
Hey Maharajan, Thank so much for the solution you provided. I was able to use the second IF condition and it worked perfectly!!
robert patriciarobert patricia
The solution that this guy has provided absolutely spot on,Thank you man for helping us out. (https://thepandahelper.com/code-free-wifi/)
Rahul Rao 28Rahul Rao 28
शादी एक ऐसा रिश्ता हैं जो दो आत्माओ 💑 को जोड़े रखता हैं। शादी सात जन्मों का प्यार भरा रिश्ता हैं। शादी की सालगिरह हर एक के जीवन में सबसे खास दिनों में से एक है। शादी की सालगिरह की शुभकामनाएं (https://lovegram.in/happy-marriage-anniversary-wishes-message-and-quotes-in-hindi/)।
यदि आप किसी ऐसे जोड़े के करीब हैं जो जल्द ही अपनी शादी की सालगिरह 💝 मनाने की योजना बना रहा है, तो आपको विशेष अवसर के लिए उन्हें कुछ विशेष शब्दों की इच्छा करने के लिए तैयार रहना चाहिए। Marriage anniversary wishes in hindi (https://lovegram.in/happy-marriage-anniversary-wishes-message-and-quotes-in-hindi/)
K P 51K P 51