You need to sign in to do that
Don't have an account?

Help - Visual force email Template - Reference to Custom object
Hi all,I am trying to create VF email template. I have account object and inside account I have custom object "Invoices", I need help how we can get "Invoices” object fields into template.
My sample code is –
Messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Invoice__c">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
<messaging:htmlEmailBody >
<b> Dear {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your Virtuagym subscription for the total amount of currency_and_total_amount. <br/>
<table>
<tr>
<th>Invoice Number</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Account_invoice__r}" >
<tr>
<td>{!cx.Invoice_Number__c}</td>
</tr>
</apex:repeat>
</table>
I am also getting error – “Error: Invalid field Invoice_Number__r for SObject Account”
Additional Info :-
- Invoice__c : Is API name of my Custom Object Invoices
- Account_invoice__c - Child Relationship Name of Invoices with Accounts
My sample code is –
Messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Invoice__c">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
<messaging:htmlEmailBody >
<b> Dear {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your Virtuagym subscription for the total amount of currency_and_total_amount. <br/>
<table>
<tr>
<th>Invoice Number</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Account_invoice__r}" >
<tr>
<td>{!cx.Invoice_Number__c}</td>
</tr>
</apex:repeat>
</table>
I am also getting error – “Error: Invalid field Invoice_Number__r for SObject Account”
Additional Info :-
- Invoice__c : Is API name of my Custom Object Invoices
- Account_invoice__c - Child Relationship Name of Invoices with Accounts
All Answers
Code changed as per your comment -
<messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Account">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
<messaging:htmlEmailBody >
<b> Dear {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your Virtuagym subscription for the total amount of currency_and_total_amount. <br/>
<table>
<tr>
<th>Invoice Number</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Account_invoice__c}" >
<tr>
<td>{!cx.Account.Invoice_Number__c}</td>
</tr>
</apex:repeat>
</table>
Best regards,<br/>
Virtuagym Collection department<br/>
Herengracht 250, 1016 BV Amsterdam, the Netherlands<br/>
www.virtuagym.com<br/>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
needs to be
Field descriptions -
Invoice_Number__c -:- is the one of the field in custom object "Invoices"
Invoices__r :- Master-Detail Options - Child Relationship Name (Invoices) , related to (Account)
Code changed -
<messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Account">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
<messaging:htmlEmailBody >
<b> Dear {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your subscription. <br/>
<table>
<tr>
<th>Invoice Number</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Invoices__r}" >
<tr>
<td>{!cx.Invoice_Number__c}</td>
</tr>
</apex:repeat>
</table>
Best regards,<br/>
Collection department<br/>
BV Amsterdam, the Netherlands<br/>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
but after sucessful execution of this code , I am getting below output which has no values displayed.. can you please help
Dear
Our financial records show that we have not yet received funds for your subscription.
Invoice Number
Best regards,
Collection department
BV Amsterdam, the Netherlands
i can see Output now -
Dear Lead-21-Aug-2017-1018
Our financial records show that we have not yet received funds for your subscription.
Invoice Number
0015E00000N2UEkQAN
0015E00000N2UEkQAN
Best regards,
Collection department
BV Amsterdam, the Netherlands
but i am getting salesforce Id, I want actual Invoice number.
can you please help ?
You could check this by adding text within the repeat: The word Test should be printed in the output for each invoice.
If Test is printed check field accessability for Invoice_Number__c and if data is actually available.
Output still Coming as -
1-
Dear Vishal-29-Aug-2017-1138
Our financial records show that we have not yet received funds for your subscription.
Test
Invoice NumberPayment Due DateAmount DuePayment Reference
0015E00000NWlyfQADTue Aug 29 00:00:00 GMT 2017-54.0128
Best regards,
Collection department
BV Amsterdam, the Netherlands
2- Also date is not coming in Proper format
My code -
<messaging:emailTemplate subject="Dunning Reminder" recipientType="Contact" relatedToType="Account">
<!-- <messaging:plainTextEmailBody >
Congratulations!
This is your new Visualforce Email Template.
</messaging:plainTextEmailBody> -->
<messaging:htmlEmailBody >
<b> Dear {!relatedTo.Name} </b><br/>
Our financial records show that we have not yet received funds for your subscription. <br/>
<table>
<tr>
<th>Invoice Number</th>
<th>Payment Due Date</th>
<th>Amount Due</th>
<th>Payment Reference</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Invoices__r}" >
Test
<tr>
<td>{!cx.Account_invoice__c}</td>
<td>{!cx.Transaction_Due_Date_del__c}</td>
<td>{!cx.Amount_FC__c}</td>
<td>{!cx.Account_Code__c}</td>
</tr>
</apex:repeat>
</table>
Best regards,<br/>
Collection department<br/>
BV Amsterdam, the Netherlands<br/>
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Data into Salesforce
Invoice Number 17700085
Transaction Due Date 29-8-2017
Amount FC EUR -54,00
Payment Reference 128
Account_invoice__c is probably the lookup field for account on your invoice__c object. You need to replace it with the field containing your invoice number.
Date formatting is done by using apex:outputtext, more information can be found here:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm
but this is no longer related to your initial question for referencing a custom object. Please select the appropriate answer as the solution to your question.
ur right, I have used incorrect field.
Now output looks okie !
If i want to use rhe field from Standard obejct how can add APi field name.
Currently I have added as per below but it's giving me an error - Error: Invalid field Billing_VAT_Code__c for SObject Invoice__c
Billing_VAT_Code__c is the field from Account Object.
My code is -
<messaging:emailTemplate subject="Dunning 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">
<b> Dear {!relatedTo.Name} </b><br/>
<br/>
Our financial records show that we have not yet received funds for your subscription. <br/>
<br/>
<table border="0" >
<tr>
<th>Invoice Number</th>
<th>Payment Due Date</th>
<th>Currency</th>
<th>Amount Due</th>
<th>Payment Reference</th>
<th>Billing VAT Code</th>
</tr>
<apex:repeat var="cx" value="{!relatedTo.Invoices__r}" >
<tr>
<td>{!cx.Invoice_Number__c}</td>
<td>{!cx.Transaction_Due_Date_del__c}</td>
<td>{!cx.Currency__c}</td>
<td>{!cx.Amount_FC__c}</td>
<td>{!cx.Account_Code__c}</td>
<td>{!cx.Billing_VAT_Code__c}</td>
</tr>
</apex:repeat>
</table>
</font>
<br/>
<br/>
<br/>
Best regards,<br/>
Collection department<br/>
BV Amsterdam, the Netherlands<br/>
</messaging:htmlEmailBody>
</messaging:emailTemplate>