1

This is my Visual force email template :

Controller

public class casetemplate{

    public id accountid{get;set;}

    public list<case> getcases(){

        List<case> caselist= [SELECT CaseNumber,Description,ContactEmail,ContactMobile,ContactPhone,CreatedDate,OwnerId FROM Case where accountid =:accountid ];
        return caselist;
    }
}

Component

<apex:component controller="casetemplate" access="global">
    <apex:attribute name="accttid" type="id"  description="Id of account" assignTo="{!accountid}"/>
    <table>
        <tr>
            <td>Case Number</td>
            <td>Case Description</td>
        </tr>
        <apex:repeat value="{!cases}" var="c">
            <tr>
                <td>{!c.casenumber}</td>
                <td>{!c.description}</td>
            </tr>
        </apex:repeat>
    </table>
</apex:component>

Email Template

<messaging:emailTemplate subject="Case Description :Case.description    Created Date :    Owner :" recipientType="Contact" relatedToType="account">
    <messaging:htmlEmailBody >
        <br>This is the list of cases for your account {!relatedto.name}</br>
        <br><c:Casecontacttemplate accttid="{!relatedto.id}"/></br>

    </messaging:htmlEmailBody>
</messaging:emailTemplate>

I want my email subject to dynamically populate Case Description : ,Created Date : ,Owner : ,fields from case .So this is what my subject of email template should look like

Case Description : Issue with EMail Template ,Created Date :5/5/2017 ,Owner :Natasha williams

  • I also tried this way <messaging:emailTemplate subject="Case Description :{!relatedto.account.Cases__r.description } " recipientType="Contact" relatedToType="account"> and this too <messaging:emailTemplate subject="Case Description :{!relatedto.Cases__r.description } " recipientType="Contact" relatedToType="account"> but nothing helped – Natasha May 6 '17 at 13:04
  • Okay ,I just figured it out , Posting the updated code here so that it could help someone else :-) <messaging:emailTemplate subject="Case Description :{!relatedto.Description } Created Date : {!relatedto.CreatedDate} Owner :{!relatedto.OwnerId}" recipientType="Contact" relatedToType="account"> <messaging:htmlEmailBody > <br>This is the list of cases for your account {!relatedto.name}</br> <br><c:Casecontacttemplate accttid="{!relatedto.id}"/></br> <apex:repeat var="cx" value="{!relatedTo.Cases}"> </apex:repeat> </messaging:htmlEmailBody> </messaging:emailTemplate> – Natasha May 6 '17 at 13:23
  • 2
    can you try pasting your last comment as an answer, and as for your first comment, update your question so it includes it, this is not a very good use for the comment ssection – glls May 6 '17 at 14:06
2

Okay ,I just figured it out , Posting the updated code here so that it could help someone else :-)

<messaging:emailTemplate subject="Case Description :{!relatedto.Description } Created Date : {!relatedto.CreatedDate} Owner :{!relatedto.OwnerId}" recipientType="Contact" relatedToType="account"> <messaging:htmlEmailBody > <br>This is the list of cases for your account {!relatedto.name}</br> <br><c:Casecontacttemplate accttid="{!relatedto.id}"/></br> <apex:repeat var="cx" value="{!relatedTo.Cases}"> </apex:repeat> </messaging:htmlEmailBody> </messaging:emailTemplate>
|improve this answer|||||

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.