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
BobPBobP 

apex repeat multiple rows from a single record

I was wondering if it is possible to acheive creating a visualforce page with using  apex:repeat that looks similar to my screenshot below. primarly I'm looking at the Payment Schedule section

User-added image
Best Answer chosen by BobP
mohd anasmohd anas
Hi BobP,
Your wrapper can be something simmilar to the one below.
public class Wrapper{
    public string siteName;
    public string address;
    public string city;
    public string ST;
    public Integer zipCode;
    public List<quater> quater;
    
    public class quater{
        public Decimal total;
        public List<payment> payments;
    }
    
    public class payment{
        public string monthLabel;
        public decimal amount;
    }   
    
}

then you can fill the List<wrapper> in the controller and can use the repeat simmilar as below to get same output as you,

<table>
        <!-- Table Header -->
        <tr>
                <td> Site Name </td>
                <td> Address </td>
                <td> City </td>
                <td> ST </td>
                <td> Zipcode </td>
                <td> Payment Schedule</td>
        </tr>
        <!-- Data Block -->
        <apex:repeat var="wrap" value="{!wrapperList}" >
            <tr>
                <td> {!wrap.siteName} </td>
                <td> {!wrap.address} </td>
                <td> {!wrap.city} </td>
                <td> {!wrap.ST} </td>
                <td> {!wrap.zipCode}</td>
                <td>
                    <table>
                        <apex:repeat var="quater" value="{!wrap.quater}">
                            <tr>
                                <apex:repeat var="payment" value="{!quater.payments}">
                                    <td>
                                        <table>
                                            <tr>
                                                <td>{!payment.monthLabel}</td>
                                            </tr>
                                            
                                            <tr>
                                                <td>$ {!payment.amount}</td>
                                            </tr>
                                        </table>
                                    </td>
                                </apex:repeat>
                                
                                <td>
                                    {!quater.total}
                                </td>
                            </tr>
                        </apex:repeat>
                    </table>
                </td>
            </tr>
        </apex:repeat>
    </table>
 


I hope it helps

All Answers

mohd anasmohd anas

Hi Bobp,

Yes it is very much possible to create, you just have to design a wrapper class similar to this one record row (can also be nested wrapper as well), once you are done with that in  the backend controller of this vf page,then create the list of the wrapper with the values in it and then it becomes very simple as you only have to iterate over the list of the outer and inner wrappers (in case of nested wrapper). 

i hope it helps, do let me know if you need my help in creating the wrapper.

 

BobPBobP
Hi Mohd, 
I'm not sure how to create that type of wrapper class for this type of requirement. Is there so sort of example you could post for me? 
 
mohd anasmohd anas

Hi BobP,

I don't have any example at hand right now but can help you create your wrapper if you could provide me some details on the single row

not your salesforce object structure but more like 
One site (Acme Company) can have more than 6 payment schedule  and its devided in quaters each block 

similar to this.


 

BobPBobP


Here is what my vf page looks like. Problem is it create a bunch of pages which we are trying to avoid.
User-added image

Below is my VF code.
 
<apex:page standardcontroller="Account" renderas="pdf" extensions="AccountExtensionController" standardstylesheets="false" showheader="false" applyhtmltag="false">
<form >
<html xmlns="http://www.w3.org/1999/xhtml">
    <body style="color:#000000;border-style:solid; border-width:0px; width:85%; text-align:center">
    </body>

    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif;text-align:left;"
               cellpadding="2">
            
            <tr>
                <td colspan="4" style="font-size:12px; font-weight: normal">
                </td>
            </tr>
            
            <tr>
                <td colspan="4" style="font-weight:bold ; border-style:solid; border-width:1px;
                border-color:#000000;padding:3px;text-align:center;background-color:#B4C6E7;font-size:14px">
                    SERVICE PARTNER DETAILS
                </td>
            </tr>

    </table>
            
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif; text-align:left;"
               cellpadding="2">
            <tr>
                <td width="50%" align="left" style="color: #000000;text-align:left; border-left-style: solid; border-left-width: thin;
                border-left-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px;padding-top:10px">
                    <b>Company</b> {!Account.Name}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                <td width="50%" align="right" style="color: #000000;text-align:left; border-right-style: solid; border-right-width: thin;
                border-right-color:#ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px;padding-top:10px">
                    <b>Office Phone</b> {!Account.Phone}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            </tr>
            <tr>
                <td width="25%" align="left" style="color: #000000;text-align:left; border-left-style: solid; border-left-width: thin;
                border-left-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px">
                    <b>Contact</b> {!Account.Primary_Field_POC__r.FirstName} {!Account.Primary_Field_POC__r.LastName} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                <td width="25%" align="left" style="color: #000000;text-align:left; border-right-style: solid; border-right-width: thin;
                border-right-color:  #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px"><b>Cell Phone</b> {!Account.Secondary_Phone__c}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td width="25%" align="left" style="color: #000000;text-align:left; border-left-style: solid; border-left-width: thin;
                border-left-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px">
                    <b>Street Address</b><br/> {!Account.BillingStreet}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                <td width="25%" align="left" style="color: #000000;text-align:left; border-right-style: solid; border-right-width: thin;
                border-right-color:#ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px"><b>Fax</b> {!Account.Fax}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </td>
            </tr>
            
            <tr>
                <td width="25%" align="left" style="color: #000000;text-align:left; border-left-style: solid; border-left-width: thin;
                border-left-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px">
                    <b>City, St. Zip</b><br/> {!Account.BillingCity}, {!Account.BillingState} {!Account.BillingPostalCode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td width="25%" align="left" style="color: #000000;text-align:left; border-right-style: solid; border-right-width: thin;
                border-right-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding-bottom:10px"><b>Email</b> {!Account.Primary_Field_POC__r.Email}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="4" style="font-weight:bold ; border-style: solid; border-width:1px;
                border-color: #000000;padding:3px;padding:3px;text-align:center;background-color:#B4C6E7;font-size:14px">PER PUSH SERVICE AGREEMENT</td>
            </tr>
    </table>
            
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif;  text-align:left;"
               cellpadding="4">
          
            <tr>
               
            <td width="50%" align="left" style="color: #000000;text-align:center; border-right-style: solid; border-right-width: thin;
                border-right-color: #ffffff;font-style:normal; font-weight:normal;font-size:12px;padding:3px">Per Push Fees: Includes all fees necessary to complete the services described in the scope of work for the event duration. Hourly pricing applies only to extra services.
            </td>
            </tr>
    </table>
 
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif;text-align:center;" cellpadding="2">
            
            <tr>
                <td colspan="4" style="font-size:12px; font-weight: normal">
                </td>
            </tr>
            
            <tr>
                <td colspan="4" style="font-weight:bold ; border-style: solid; border-width:1px;
                border-color:#000000;padding:3px;background-color:#B4C6E7;font-size:14px">
                  Service Locations and Fees
                </td>
            </tr>
        
    </table>
   
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif; text-align:center;font-size:12px"
               cellpadding="0">
              
            <apex:repeat var="sd" value="{!bidsList}">
          
              <apex:outputPanel layout="none" rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}" style="vertical-align:central; font-family: Arial, Helvetica, sans-serif; text-align:center;width:85%">
                  
                    <tr>
                        <th style="text-align:center;background-color:#0094DA;border-bottom-style:solid;border-bottom-width:1px;border-top-width:1px; border-top-style:solid">Site Name</th>
                        <th style="text-align:center;background-color:#0094DA;border-bottom-style:solid;border-bottom-width:1px;border-top-width:1px; border-top-style:solid">Service Period</th>
                        <th style="text-align:center;background-color:#0094DA;border-bottom-style:solid;border-bottom-width:1px;border-top-width:1px;border-top-style:solid">Address</th>
                    </tr>

                   </apex:outputPanel>
                 
                <apex:outputPanel layout="none" rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}" style="vertical-align:central;font-family: Arial, Helvetica, sans-serif; text-align:center;width:85%">
                   
                    <tr>
                       
                        <td style="font-weight:bold ; border-bottom-style:solid; border-bottom-width:1px;
                            color:#000000;padding:3px;text-align:center;background-color:#f2f2f2" ><apex:outputPanel rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}"> {!sd.Customer__r.Name }</apex:outputPanel> </td>
                       
                       <td style="font-weight:bold ; border-bottom-style:solid; border-bottom-width:1px;
                            color:#000000;padding:3px;text-align:center;background-color:#f2f2f2" ><apex:outputPanel rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}"> <apex:outputText value="{0, date, MMMM d','  yyyy}">
                        <apex:param value="{!sd.Customer__r.Contract_Start_Date__c}" /> </apex:outputText> - <apex:outputText value="{0, date, MMMM d','  yyyy}"><apex:param value="{!sd.Customer__r.Contract_End_Date__c}" /></apex:outputText>

                </apex:outputPanel></td>

                       <td style="font-weight:bold ; border-bottom-style:solid; border-bottom-width:1px;
                            color:#000000;padding:3px;text-align:center;background-color:#f2f2f2" ><apex:outputPanel rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}">{!sd.Site__r.BillingStreet}&nbsp;{!sd.Site__r.BillingCity}, {!sd.Site__r.BillingState} {!sd.Site__r.BillingPostalCode} </apex:outputPanel></td>

                    </tr>

                </apex:outputPanel>
               
                       <apex:repeat var="et" value="{!bidsMap[sd.Name] }" rendered="{!IF(sd.IsAddedToPDF__c =true  ,true,false)}"    >
    
                   <tr>
                       <th style="text-align:center;background-color:#28baff;border-bottom-style:solid;border-bottom-width:1px;border-top-width:0px; border-top-style:solid">Service Type</th>
                       <th style="text-align:center;background-color:#28baff;border-bottom-style:solid;border-bottom-width:1px;border-top-width:0px; border-top-style:solid">Service Desciption</th>
                       <th style="text-align:center;background-color:#28baff;border-bottom-style:solid;border-bottom-width:1px;border-top-width:0px; border-top-style:solid">Pricing Schedule</th>
                   
                   </tr>

                   <tr>
                        <td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;text-align:center" class="ctr"> {!et.Bid_Name__r.Service_Type__c}</td>
                        <td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;text-align:center;text-align:center" class="ctr">{!et.Scope__c}&nbsp;{!et.Increment__c}</td>
                        <td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;text-align:center;text-align:center" class="ctr"><apex:outputText value="{0, Number, Currency}"><apex:param value="{!et.Cost__c}" /> </apex:outputText></td>
                        
                   </tr>
               </apex:repeat>
             </apex:repeat>
        </table>
     </html>
</form>

</apex:page>

 
BobPBobP
Also, i was wondering if there was a way to two apex:repeat tables side by side so that would shorten the amount of pages
mohd anasmohd anas
Hi BobP,
Your wrapper can be something simmilar to the one below.
public class Wrapper{
    public string siteName;
    public string address;
    public string city;
    public string ST;
    public Integer zipCode;
    public List<quater> quater;
    
    public class quater{
        public Decimal total;
        public List<payment> payments;
    }
    
    public class payment{
        public string monthLabel;
        public decimal amount;
    }   
    
}

then you can fill the List<wrapper> in the controller and can use the repeat simmilar as below to get same output as you,

<table>
        <!-- Table Header -->
        <tr>
                <td> Site Name </td>
                <td> Address </td>
                <td> City </td>
                <td> ST </td>
                <td> Zipcode </td>
                <td> Payment Schedule</td>
        </tr>
        <!-- Data Block -->
        <apex:repeat var="wrap" value="{!wrapperList}" >
            <tr>
                <td> {!wrap.siteName} </td>
                <td> {!wrap.address} </td>
                <td> {!wrap.city} </td>
                <td> {!wrap.ST} </td>
                <td> {!wrap.zipCode}</td>
                <td>
                    <table>
                        <apex:repeat var="quater" value="{!wrap.quater}">
                            <tr>
                                <apex:repeat var="payment" value="{!quater.payments}">
                                    <td>
                                        <table>
                                            <tr>
                                                <td>{!payment.monthLabel}</td>
                                            </tr>
                                            
                                            <tr>
                                                <td>$ {!payment.amount}</td>
                                            </tr>
                                        </table>
                                    </td>
                                </apex:repeat>
                                
                                <td>
                                    {!quater.total}
                                </td>
                            </tr>
                        </apex:repeat>
                    </table>
                </td>
            </tr>
        </apex:repeat>
    </table>
 


I hope it helps

This was selected as the best answer