You need to sign in to do that
Don't have an account?
Melissa Parker 17
Invalid field for SObject when building a table of data in a Visualforce page
I am attempting to create a Visualforce Email template that basically emails the contact and shows its related list of Assignments__c in the template.
I am following the document here: https://developer.salesforce.com/page/VisualForceEmailTemplates_sample
However I am receiving an error: Error: Invalid field Contact for SObject Assignments__c
<messaging:emailTemplate subject="Tomorrow's Inspections and Homeowner Closing Appointments"
recipientType="Contact"
relatedToType="Assignments__c">
<messaging:htmlEmailBody >
<html>
<body>
<p>Dear {!recipient.name},</p>
<p>Attached is your inspection schedule for tomorrow. Please review it to make sure there is enough time allowed between inspections.
Call Rick Werts (863) 207-6550 with any changes that are necessary to make sure we are making every appointment on time.
Thank you for all of your hard work out there.
Thank you,
Bill Todd
V.P. of Sales
</p>
<table border="0" >
<tr>
<th>Policyholder Name</th><th>Risk Street</th>
<th>Risk City</th><th>Risk State</th>
<th>Risk Zip Code</th><th>Inspection Date and time</th>
<th>Homeowner Closing Appt</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Contact.Assignments__c}">
<tr>
<td><a href =
"https://cs50.salesforce.com/{!cx.id}">{!cx.Assignments.Name}
</a></td>
<td>{!cx.Assignments.Risk_Street_Address__c}</td>
<td>{!cx.Assignments.Risk_State_Address__c}</td>
<td>{!cx.Assignments.Risk_City__c}</td>
<td>{!cx.Assignments.Risk_Zip_Code_Address__c}</td>
<td>{!cx.Assignments.Inspection_Date_and_Time__c}</td>
<td>{!cx.Assignments.Homeowner_Closing_Appt__c}</td>
</tr>
</apex:repeat>
</table>
<p/>
<center>
<apex:outputLink value="http://www.salesforce.com">
For more detailed information login to Salesforce.com
</apex:outputLink>
</center>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
I am following the document here: https://developer.salesforce.com/page/VisualForceEmailTemplates_sample
However I am receiving an error: Error: Invalid field Contact for SObject Assignments__c
<messaging:emailTemplate subject="Tomorrow's Inspections and Homeowner Closing Appointments"
recipientType="Contact"
relatedToType="Assignments__c">
<messaging:htmlEmailBody >
<html>
<body>
<p>Dear {!recipient.name},</p>
<p>Attached is your inspection schedule for tomorrow. Please review it to make sure there is enough time allowed between inspections.
Call Rick Werts (863) 207-6550 with any changes that are necessary to make sure we are making every appointment on time.
Thank you for all of your hard work out there.
Thank you,
Bill Todd
V.P. of Sales
</p>
<table border="0" >
<tr>
<th>Policyholder Name</th><th>Risk Street</th>
<th>Risk City</th><th>Risk State</th>
<th>Risk Zip Code</th><th>Inspection Date and time</th>
<th>Homeowner Closing Appt</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Contact.Assignments__c}">
<tr>
<td><a href =
"https://cs50.salesforce.com/{!cx.id}">{!cx.Assignments.Name}
</a></td>
<td>{!cx.Assignments.Risk_Street_Address__c}</td>
<td>{!cx.Assignments.Risk_State_Address__c}</td>
<td>{!cx.Assignments.Risk_City__c}</td>
<td>{!cx.Assignments.Risk_Zip_Code_Address__c}</td>
<td>{!cx.Assignments.Inspection_Date_and_Time__c}</td>
<td>{!cx.Assignments.Homeowner_Closing_Appt__c}</td>
</tr>
</apex:repeat>
</table>
<p/>
<center>
<apex:outputLink value="http://www.salesforce.com">
For more detailed information login to Salesforce.com
</apex:outputLink>
</center>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Try this:
<apex:repeat var="cx" value="{!relatedTo.Contact.Assignments__c}">
to
<apex:repeat var="cx" value="{!relatedTo.Contact__r.Assignments__c}">
If there is any issue then let us know the field name of Contact on Assignment__c object.
Regards,
Mahesh
The contact lookup field on the Assignment__c object is called:
Thanks for all your help!!!
https://developer.salesforce.com/page/VisualForceEmailTemplates_sample
It shows using the plural form of the child related list for an email set up like so:
1<messaging:emailTemplate recipientType="Contact"
2 relatedToType="Account"
The related list on Accounts that is being added to the email is Cases:
<apex:repeat var="cx" value="{!relatedTo.Cases}">
In this example, relatedToType gives us access to the parent object for "Contact" so that we can access a different child object, "Case", on that same parent.
Since you are using a related list Assignments__r (*note that the related list uses the defined plural form and has __r suffix rather than the __c suffix*) on the Contact object, you should be able to just set value={!Contact.Assignments__r}.
Another good doc reference is found here:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_custom_mapping.htm
Error: Unknown property 'core.email.template.EmailTemplateComponentController.Contact'
Also you have to know the child relationship name for this Lookup.
Regards,
Mahesh
I'm not sure what you mean that I will need to know the child relationship for this lookup. From the Assignments object there is a lookup to the contact object called Inspector_lookup__c. Thats all there is to it. I have posted the entire code again with the update. Thanks again for the help.
<messaging:emailTemplate subject="Tomorrow's Inspections and Homeowner Closing Appointments"
recipientType="Contact"
relatedToType="Assignments__c">
<messaging:htmlEmailBody >
<html>
<body>
<p>Dear {!recipient.name},</p>
<p>Below is your inspection schedule and for tomorrow. Please review it to make sure there is enough time allowed between inspections.
Call Rick Werts (863) 207-6550 with any changes that are necessary to make sure we are making every appointment on time.
Thank you for all of your hard work out there.
Thank you,
Bill Todd
V.P. of Sales
</p>
<table border="0" >
<tr>
<th>Policyholder Name</th><th>Risk Street</th>
<th>Risk City</th><th>Risk State</th>
<th>Risk Zip Code</th><th>Inspection Date and time</th>
<th>Homeowner Closing Appt</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Inspector_Lookup__r.Assignments__r}">
<tr>
<td><a href =
"https://cs50.salesforce.com/{!cx.id}">{!cx.Assignments.Name}
</a></td>
<td>{!cx.Assignments.Risk_Street_Address__c}</td>
<td>{!cx.Assignments.Risk_State_Address__c}</td>
<td>{!cx.Assignments.Risk_City__c}</td>
<td>{!cx.Assignments.Risk_Zip_Code_Address__c}</td>
<td>{!cx.Assignments.Inspection_Date_and_Time__c}</td>
<td>{!cx.Assignments.Homeowner_Closing_Appt__c}</td>
</tr>
</apex:repeat>
</table>
<p/>
<center>
<apex:outputLink value="http://www.salesforce.com">
For more detailed information login to Salesforce.com
</apex:outputLink>
</center>
</body>
</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
You can find the relationship names for objects in Setup.
On the Conact, there is an Assignment List.
I already did but here it is again:
You can try this:
Regards,
Mahesh