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
Admin User 8648Admin User 8648 

visualforce email template with Apex Repeat adds Rows rather than Columns

Hi ,

I am trying to ad a Table in Visualforce Email Template which will pull up all child records.
My code is working fine with pulling data However , Its adding mutiple rows for every new record instead of adding up Columns.

Can anybody help me identifying whats wrong? Below is my Table  :-
 
<table border="0"  align="center" width="300">
        <caption>Parts Requested</caption>
        <apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
       
             <tr>
    <th> Model Number</th>
    <td>{!cx.Model_Number__c}</td>
             </tr>
             
             <tr>
    <th> Serial Number</th>
    <td> {!cx.Serial_Number__c}</td>
             </tr>
             
             <tr>
    <th> Part Number</th>
    <td> {!cx.Part_Number__c}</td>
             </tr>
             
             <tr>
    <th> Part Description</th>
    <td> {!cx.Part_Description__c}</td>
             </tr>
             
             <tr>
    <th> Quantity</th>
    <td> {!cx.Quantity__c}</td>
             </tr>
             
             <tr>
    <th>Reason </th>
    <td> {!cx.Reason__c}</td>
             </tr>
    
           </apex:repeat>                
        </table>

 
Suraj GharatSuraj Gharat
The problem is with your HTML markup. Try below code instead.
 
<table border="0"  align="center" width="300">
        <caption>Parts Requested</caption>
		<tr>
			<th> Model Number</th>
			<th> Serial Number</th>
			<th> Part Number</th>
			<th> Part Description</th>
			<th> Quantity</th>
			<th> Reason </th>
		</tr>
        <apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
       
             <tr>
    <td>{!cx.Model_Number__c}</td>
             
    <td> {!cx.Serial_Number__c}</td>
             
    <td> {!cx.Part_Number__c}</td>
             
    <td> {!cx.Part_Description__c}</td>
             
    <td> {!cx.Quantity__c}</td>
             
    <td> {!cx.Reason__c}</td>
             </tr>
    
           </apex:repeat>                
        </table>

HTH,
Suraj Gharat​​​​​​​
Admin User 8648Admin User 8648
Hi Suraj , This wont solve the issue , I want to have a vertical chart and this will make it horizontal. 
Admin User 8648Admin User 8648
The Headers should be vetical rows and , each child record should add a Column with Data .
Suraj GharatSuraj Gharat
We need to prepare needed data in a map for optimal use in VF markup. Or else we need to apply row-column inversion logic using JS or CSS.

Anyway below is clearly not the right way to do this, but may work.
 
<table border="0"  align="center" width="300">
        <caption>Parts Requested</caption>  
		<tr>
			<th>
				Model Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Model_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Serial Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Serial_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Part Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Part_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Part Description
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Part_Description__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Quantity
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Quantity__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Reason
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Reason__c}</td>
				</td>
			</apex:repeat>
		</tr>
        </table>

 
Admin User 8648Admin User 8648
This is giving desired result. Is there any way to add Column Numbering for new Child record like Child rec 1 , CHild rec 2 ,child rec 3 and so on ....or  will it be too much for this ?
Suraj GharatSuraj Gharat
Not sure if this works
<table border="0"  align="center" width="300">
        <caption>Parts Requested</caption>  
		<tr>
			<th></th>
			<apex:variable var="i" value="{!1}" />
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<th>Child Record - {!i}</th>
				<apex:variable var="i" value="{!i+1}" />
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Model Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Model_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Serial Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Serial_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Part Number
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Part_Number__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Part Description
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Part_Description__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Quantity
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Quantity__c}</td>
				</td>
			</apex:repeat>
		</tr>
		<tr>
			<th>
				Reason
			</th>
			<apex:repeat var="cx" value="{!relatedTo.Product_Request_Line_Items__r}"> 
				<td>
					<td>{!cx.Reason__c}</td>
				</td>
			</apex:repeat>
		</tr>
        </table>

 
Admin User 8648Admin User 8648
Wow. I think we are very very close . This almost there . Its just its adding firsts Child Rec as Blank column and then adding value from Child rec 2 column and so on .......