0

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>
  • Your example has identical <tr> ...</tr> blocks; is one meant to refer to checkout__c ? – cropredy Apr 16 '14 at 15:51
  • @crop1645 i update my code. – Sathya Apr 16 '14 at 15:53
6

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>
  • i am getting below error Error occurred trying to load the template for preview: The value 'null' is not valid for operator '>'.. Please try editing your markup to correct the problem. – Sathya Apr 16 '14 at 16:00
  • You must first test your var if it not null ! – melmoussaoui Apr 16 '14 at 16:02

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.