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
WebNXWebNX 

Creating a Visualforce Template For Task

I am try to create a visualforce template to display all the task that a user(s) may have open the following day, but I am receiving this error inside salesforce when I save my code. Here is the error message:

Error: Invalid field Task for SObject Task 

Can some body please help me, and tell me where I am going wrong in visualforce. Thanks, also below is my visualforce code:

 

<messaging:emailTemplate subject="Task For Today" recipientType="User" relatedToType="Task">
<messaging:htmlEmailBody>
<html>
<style type="text/css">
    body{font-family: Courier; size: 12pt;}
        table{
        border-width: 5px;
        border-spacing: 5px;
        border-style: line;
        border-color: #FF0000;
        background-color: #FFFFFF;
        }
        
    td {
            border-width: 1px;
            padding: 4px;
            border-style: solid;
            border-color: #000000;
            background-color: #FFEECC;
        }

    th {
            color: #000000;
            border-width: 1px ;
            padding: 4px ;
            border-style: solid ;
            border-color: #000000;
            background-color: #FFFFF0;
        }
</style>
<body>
    <p>Dear {!recipient.name},<br />
    Below is a list of task(s) that are assign to you, for today!
    </p>
        <table border="0" >
            <tr>
                <th>Subject</th><th>Name of Lead</th>
                <th>Name of Contact</th><th>Phone #</th>
                <th>Lead's Email</th><th>Contact Email</th>
            </tr>
            <apex:repeat var="cx" value="{!relatedTo.Task}">
            <tr>
                <td>{!cx.Subject}</td>
                <td>{!cx.Lead.Name}</td>
                <td>{!cx.Contact.Name}</td>
                <td>{!cx.Phone}</td>
                <td>{!cx.Lead.email}</td>
                <td>{!cx.Contact.email}</td>
            </tr>
                </apex:repeat>
        </table>
    </body>
    </html>
    </messaging:htmlEmailBody></messaging:emailTemplate>

IspitaIspita

Hi,

The try removing /comment the following fields referred by you:-

 

                <td>{!cx.Lead.Name}</td>

                <td>{!cx.Contact.Name}</td>
                <td>{!cx.Lead.email}</td>
                <td>{!cx.Contact.email}</td>

 

and check if the error persists , if the error goes away let me know , then I will tell you the reason ....

WebNXWebNX

I tried that and that didn't work. I even tried removing the fields that you mention and just leave the Subject field in and I am still getting an error. Do you have any more ideas what it could be causing this error?

 

Thanks for your help.

hemantgarghemantgarg

 I saw your relatedToType is Task and you are referencing relatedTo.Task, means it is "Task.Task", that obviously does not mean anything.

But yes I have tried it by changing the RelatedToTYpe from Task to User, and then in repeat , I referenced relatedTo.Tasks , it is also not working, there must be some gotcha.

WebNXWebNX

Hey hemantgarg,

 

I am thinking the same thing. I am starting to believe that we are not able to create user custom templates, that templates can only target leads and contacts; that templates are not used for internal people like users.

 

Thanks,

 

WH