I try to create Visualforce Email Template in order to send our Purchase order (BC) to the supplier So I need to insert inside the mail , all (BC line items ) I begin to create HTML+CSS code , but after with apex , there is an error and I can’t find where is it ?
after testing with the code below I have this kind of message :
Error: Unknown property ‘String.Name’
<messaging:emailTemplate subject="Bon de Commande - Purchase order" recipientType="User" relatedToType="BC_Line_Item__c"> <messaging:plainTextEmailBody > <html> <body> <div id="reference"> <span> - Customer PO : </span> {!relatedTo.BC__c.PO_Number__c} </div> <table> <thead> <tr> <th class="desc">Description</th> <th>Customer Code </th> </tr> </thead> <tbody> <apex:repeat var="opp" value="{!relatedTo.BC_Line_Item__c}"> <tr> <td class="desc">'{!opp.Product__c}'</td> <td class="baan">{!opp.Customer_Number__c}</td> </tr> </apex:repeat> </body> </html> </messaging:plainTextEmailBody> </messaging:emailTemplate>
I try to change relatedToType to BC__c instead of BC_Line_Item__c and changing the field but the error is : Error: Invalid field BC_Line_Item__c for SObject BC__c
<messaging:emailTemplate subject="Bon de Commande - Purchase order" recipientType="User" relatedToType="**BC__c**"> <messaging:plainTextEmailBody > <span> Number : </span> {!relatedTo.Name} <apex:repeat var="opp" value="{!relatedTo.BC_Line_Item__c}"> <tr> <td class="desc">'{!opp.Product__c}'</td> <td class="baan">'{!opp.Customer_Number__c}'</td> </tr> </apex:repeat>
After checking , there are two Objects : BC and BC_Line_Item
Thanks in advance
for more details about the code please Code Source
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The VF email template relatedToType
should be BC__c
as this is the Purchase Order
The apex:repeat needs to iterate over the relationship from Purchase Order to line items – whose name will be BC_line_items__r
, not BC_line_item__c
.
You can see a similar example (Account with Cases) in the VF doc
You are also including HTML inside of a <messaging:plainTextEmailBody >
set of tags rather than <messaging:htmlEmailBody >
set of tags
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0