I have a VF template where I need to vary the closing part of the mail(after 'Best Regards') based on a particular Picklist field on the case object.

Eg if Custom_field__c ='ML' then the closing part of the email should be - ABC if Custom_field__c ='SS' then the closing part of the email should be - CFG and a few similiar conditions. My code here does not seem to work

 <messaging:emailTemplate subject="{!relatedTo.Subject}, 

        {!relatedTo.CaseNumber} {!relatedTo.ThreadId__c}" 
        recipientType="Contact" relatedToType="Case">
        <messaging:htmlEmailBody >

<STYLE type="text/css">   
td.content{font-size: 14px; font-face: Verdana; text-align: left}  

  <td class="content">       
 <br> Should you have any further enquiries, you may simply reply to this email.</br>      

   <apex:repeat var="cs" value="{!relatedTo}">
   <apex:outputpanel rendered="{If(ISPICKVAL(cs.Custom_field__c ,'Maersk Line')true,false)}">

      <br>Kind Regards,</br>


2 Answers 2


As mentioned by Tushar, relatedTo is a single record, not a list. Merge fields always start with {! and end with }. You forgot the !. Also, you don't need an "IF" statement here:

rendered="{!ISPICKVAL(relatedTo.Custom_field__c ,'Maersk Line')}"
  • Good catch totally missed it. Commented May 4, 2018 at 10:46
  • @gopal1007 Yes, ISPICKVAL is only for picklists; I used it under the impression from your code that it was actually a picklist.
    – sfdcfox
    Commented May 4, 2018 at 11:18
  • It is a picklist field. But I am not sure why it is returning a text tho!
    – gopal1007
    Commented May 4, 2018 at 11:19
  • 1
    just a note that visualforce appears to treat picklists like text - so pickval throws an error "Incorrect parameter type for function 'ISPICKVAL()'. Expected Picklist, received Text". This behavior is supported by this sfse post - so just using a regular == comparison operator instead is working
    – gorav
    Commented Apr 6, 2020 at 17:46

As RelatedTo refer to a single object so we don't need apex:repeat here.

<apex:outputpanel rendered="{!ISPICKVAL(relatedTo.Custom_field__c ,'Maersk Line')}">

      <br>Kind Regards,</br>

</apex:outputpanel> // use same for others as well
  • I have tried your answer and it still doenst seem to work
    – gopal1007
    Commented May 4, 2018 at 10:33
  • @gopal1007 what are the output you are getting here? Commented May 4, 2018 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .