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
SFDCAdmin73SFDCAdmin73 

VF Email Template - Error occurred trying to load the template for preview.

I created a VF email template. When the email template is sent through a workflow, I need the attachments on the opportunity record to be attached to the email. Therefore I added the following code on lines 2-4.

I am recieving trhe following error:  Error occurred trying to load the template for preview: Subscript is invalid because list is empty. Please try editing your markup to correct the problem.

I am not sure how to resolve it. I appreciate any help! Thanks in advance. 
<messaging:emailTemplate subject="OEM Cost Relief (Rebate) Submitted" recipientType="User" relatedToType="OEM_Rebate_Claims__c">
<messaging:attachment filename="{!relatedTo.Attachments[0].Name}" renderAs="{!relatedTo.Attachments[0].ContentType}">
 <apex:repeat var="cx" value="{!relatedTo.Attachments}">
</apex:repeat>
</messaging:attachment>
<messaging:htmlEmailBody >        
    <html>
        <body>
        <p>Dear Ram Sridhar,</p>   
        <p> The following OEM Cost Relief (Rebate) has been submitted for your review. The rebate claim details are listed below. Attached to this email is proof of delivery.</p>        

       <STYLE type="text/css">
               TH {font-size: 14px; border:solid #CCCCCC; font-face: arial;background: #0080ff; border-width: 1; color:#ffffff; text-align: center } 
               TD  {font-size: 14px; border:solid #CCCCCC; border-width: 1; font-face: ariel; text-align: center } 
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
           <font face="ariel" size="3">
    <table>
    <tr> 
    <th>Ship Date</th><th>Invoice #</th><th>OEM</th><th>OEM Order#</th><th>QLogic Model #</th><th>Quantity Claimed</th><th>Customer Name</th><th>Customer Address</th><th>QLogic SFDC #</th><th>Claim Value Per Unit</th><th>Total Value Claimed</th></tr>
       <tr>
           <td><apex:outputText value="{0, date, MMMM d','yyyy}"><apex:param value="{!relatedTo.Ship_Date__c}" /></apex:outputText></td>
           <td>{!relatedTo.Invoice__c}</td>
           <td>{!relatedTo.OEM_Opportunity__r.OEM__c}</td>
           <td>{!relatedTo.OEM_Order__c}</td>
           <td>{!relatedTo.Product__r.Name}</td>
           <td><apex:outputText value="{0, number, #,###.00}"> <apex:param value="{!relatedTo.Quantity_Claimed__c}" /></apex:outputText></td>
           <td>{!relatedTo.Customer_Name__c}</td>
           <td>{!relatedTo.OEM_Opportunity__r.Account.Site_State_Province__c},{!relatedTo.OEM_Opportunity__r.Account.Site_Zip_Postal_Code__c},{!relatedTo.OEM_Opportunity__r.Account.Site_Country__c}</td>
           <td>{!relatedTo.QLogic_SFDC__c}</td>
           <td><apex:outputText value="{0, number, $#,###.00}"> <apex:param value="{!relatedTo.Claim_Value_Per_Unit__c}" /></apex:outputText></td>
           <td><apex:outputText value="{0, number, $#,###.00}"> <apex:param value="{!relatedTo.Total_Value_Claimed__c}" /></apex:outputText></td>
       </tr>                 
       </table> 
       
      <p>If you have any questions regarding this claims please contact {!relatedTo.OEM_Rebate_Manager__c}.</p>
      <p>Regards</p>
      <p> OEM Rebate Claim System Manager </p>
    </font>     
 </body>
  </html>
   </messaging:htmlEmailBody> 
</messaging:emailTemplate>