2

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 >

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

  <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>
          Msl 

        </apex:outputpanel>
        </apex:repeat>             
      </td>
    </tr>   
  </table>
</font>
</body>
</html>
</messaging:htmlEmailBody>

2 Answers 2

3

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')}"
4
  • 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. Commented May 4, 2018 at 11:18
  • It is a picklist field. But I am not sure why it is returning a text tho! 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 Commented Apr 6, 2020 at 17:46
0

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>
          MaerskLine 

</apex:outputpanel> // use same for others as well
2
  • I have tried your answer and it still doenst seem to work 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.