Find your content:

Search form

You are here

Visualforce Email template If condition

 
Share

I have 3 fields 1) shipping_type__c 2) Total_Shipping__c 3) CheckOut__c

when shipping_type__c = 0 at this condition i want to show CheckOut__c values in visualforce template

when shipping_type__c = 1 And 2 at this condition i want to show Total_Shipping__c fields values in email template

how can i write the if condition in visualforce email template

   <messaging:emailTemplate recipientType="Contact" relatedToType="Quote__c" subject="Your requested quote #{!relatedTo.Name}" >  
           <table>             
             <tr>                                                                    
            <td align="right"  style="width:90%">                                             
                <apex:outputText value="Shipping and handling"/></td>
                <td align="right"  style="width:10%; font-weight:bold">
                <apex:outputField value="{!relatedTo.Total_Shipping__c}"/></td>
            </tr>

            <tr>                                                                    
            <td align="right"  style="width:90%">                                             
                <apex:outputText value="Shipping and handling"/></td>
                <td align="right"  style="width:10%; font-weight:bold">
                <apex:outputField value="{!relatedTo.CheckOut__c}"/></td>
            </tr>
         </table>
      </messaging:emailTemplate>

Attribution to: Sathya

Possible Suggestion/Solution #1

Updated to test for null

The general solution to this is to use apex:outputPanel with rendered= conditions as in: (assumes shipping_type__c may be null)

<apex:outputPanel rendered="{!AND(relatedTo.shipping_type__c != null,relatedTo.shipping_type__c = 0)}">
<! -- your VF/html  here -->
</apex:outputPanel>

<apex:outputPanel rendered="{!AND(relatedTo.shipping_type__c != null,relatedTo.shipping_type__c > 0)}">
<! -- your VF/html here -->
</apex:outputPanel>

Attribution to: cropredy
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32901

My Block Status

My Block Content