1

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

2
  • Can you share your first line of the VF ?
    – Sanjay
    Jun 29, 2015 at 21:43
  • @Sanjay >> I fix the problem by writing that '<apex:repeat var="opp" value="{!relatedTo.BC_line_items__r}"> ' '<td class="desc">{!opp.Products_description__c} </td>' but I have another problem . How to display the real value of a field where the data type is a Lookup(Account) Jun 30, 2015 at 11:38

1 Answer 1

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

4
  • >> thanks , it helps me a lot . My only problem is on the product decsription . here is the code : link . the problem is at product it returns salesforce id instead of product description Jun 30, 2015 at 3:58
  • you need {!opp.Product__r.description} assuming that the Description field in the Product2 sobject has the description you are interested in. It is well worth your time to read the doc on how relationships are referenced in Salesforce (that is, for custom relationships, you use xxxx__r to traverse the relationship)
    – cropredy
    Jun 30, 2015 at 16:44
  • please I need your help I have the same problem . on template related to the sales order 'relatedToType="Sales_Order__c" >' on sales order line item I need to repeat : ' <apex:repeat var="opp" value="{!relatedTo.Sales_order_line_items__r}">' when I check the sales order line item object ; I see plural label : Sales Order Line Items . when I test it with : '{!relatedTo.Sales_order_line_items__r}"' there is an error 'Error: Invalid field Sales_order_line_items__r for SObject Sales_Order__c ' do you have an idea I don't know the rule for __r API name Jul 21, 2015 at 8:03
  • Julio - There are several ways to look up the relationship name. (1) Use the Eclipse schema browser. (2) in Force.com UI, go to the Sales_Order_Line_Item__c SObject, locate the field that is the master-detail field, then inspect the Child RelationShip Name property in the UI - Use that property value, appended by __r
    – cropredy
    Jul 21, 2015 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .