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
Vishal BirarisVishal Biraris 

Is it possible to change the subject of visual force email based on some condiitons ?

Hello all,

We would like to change the subject ""First payment reminder" " as mentioned in below sample visulaforce code, based on the some condtions.
That means, If i send first reminder email then i am going to update the field "Total remider sent" value to 1,
Then later after checking other due dates conditions, ww would like to send another email but with different Subject i.e ". "Second payment reminder" and again update Total remider sent" value to 2.
can you please help how to handle such situation, This will help me to reuse same template for all the reminder;s, Invoice information will be picked up on run time, so no issues with that.


My Visualforce working code is - 

<messaging:emailTemplate subject="First payment reminder" recipientType="Contact" relatedToType="Account">

<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->

<messaging:htmlEmailBody >
    <STYLE type="text/css">
        TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center }
        TD  {font-size: 11px; font-face: verdana }
        TABLE {border: solid #CCCCCC; border-width: 1}
        TR {border: solid #CCCCCC; border-width: 1}
     </STYLE>
     <font face="arial" size="2">

<font size="2" face="Lucida Sans Unicode" > Dear  {!relatedTo.Name}, </font><br/>
<br/>

<font size="2" face="Lucida Sans Unicode" >Our financial records show that -- subscription for the total amount {!relatedTo.CurrencyIsoCode}&nbsp;{!relatedTo.Total_Outstanding_Amount__c} </font><br/>
<br/>


 
<br/>
        <table border="0" > 
            <tr>
                <th align="right"><font size="2" face="Lucida Sans Unicode" >Invoice Number   ;</font><br/></th>
                <th align="right"><font size="2" face="Lucida Sans Unicode" >Payment Due Date   ;</font><br/></th>
                <th align="right"><font size="2" face="Lucida Sans Unicode" >Amount Due   ;</font><br/></th>
                <th align="right"><font size="2" face="Lucida Sans Unicode" >Currency   ;</font><br/></th>
                
            </tr>
            
            <apex:repeat var="cx" value="{!relatedTo.Invoices__r}" >

               <tr>
                        <td align="right"><font size="2" face="Lucida Sans Unicode" >{!cx.Invoice_Number__c}&nbsp;</font></td>
                        
                        <td align="right"><font size="2" face="Lucida Sans Unicode" >
                            <apex:outputText value="{0,date,dd'/'MMM'/'yyyy}">
                                <apex:param value="{!cx.Transaction_Due_Date_del__c}" /> 
                            </apex:outputText>&nbsp;</font>
                        </td>


                        <td align="right"><font size="2" face="Lucida Sans Unicode">&nbsp;
                            <apex:outputText style="float:right" value="{0, number, ###,##0.00}">
                                <apex:param value="{!cx.Outstanding_Amount_FC__c}"/>
                            </apex:outputText>&nbsp;</font>
                        </td>
                        
                        <td align="right"><font size="2" face="Lucida Sans Unicode" >{!cx.Currency__c}&nbsp;</font></td>
                                                                        
               </tr>
                                   
            </apex:repeat>
        </table>  
     </font>
                    
<br/>

<font size="2" face="Lucida Sans Unicode" >Our bank details:</font><br/>
<font size="2" face="Lucida Sans Unicode" >Payment reference: {!relatedTo.Exact_Online_Account_ID__c} </font><br/>
<font size="2" face="Lucida Sans Unicode" >Please do not hesitate to contact us with questions. Thank you in advance for your cooperation. </font><br/>

<br/>
<br/>
<br/>  
                
<font size="2" face="Lucida Sans Unicode" >Best regards,</font><br/>
<font size="2" face="Lucida Sans Unicode" >Collection department</font><br/>
<font size="2" face="Lucida Sans Unicode" >BV Amsterdam, the Netherlands</font><br/>
                
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Best Answer chosen by Vishal Biraris
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Hi Vishal Biraris,

It's possibe To Change the subject in visualforce page.  Don't Worry , Please follow the steps and cheers up as well.

1. Create an another one Formula field for subject (Subject__c).
2.  Apply This Formula into this field. (Before That Change the data type of Total_remider_sent__c  to text)
 
IF( Contact.Total_remider_sent__c = '1',  'First payment reminder , 'Second payment reminder')
3. Replace This code 
<messaging:emailTemplate subject="{!Contact.Subject__c}" recipientType="Contact" relatedToType="Account">

I hope This code could be usefull ... Please let me know if you have any concern.


Regards,
Soundar.
sourajking@gmail.com