I have a Custom object Quote_Bundle_Product__c and Bundle__c and Product_Quantity__c

scenario is : i have developed one visualforce page and that has functionality like user will select Quote_Bundle_Product__c.Bundle__c and based on this Bundle__c List of Product_Quantity__c records will appear automatically in Pageblocktable and this functionality is on apex:repeat so when user click on ADD BUNDLE button then repeat it accordigly

problem is : when i am going to Select Bundle__c using lookup Product_Quantity__c records will appear correctly (see Image 1.0) and then user will click on ADD BUNDLE then it's automatically show up the Previous List of Records(See Image 2.0), also new Bundle with New List is there on same section(See Image 3.0)

Image 1.0 enter image description here

Image 2.0 enter image description here

Image 3.0 enter image description here

let me share my code here so it's more clear to understand

Visualforce Page :

<apex:pageBlock >
            <apex:pageBlockButtons location="Bottom">
                <apex:commandButton value="Add Bundle" action="{!addSection2}"/>
<apex:repeat value="{!QBPList}" var="QL">
<apex:variable value="" var="foo" rendered="{!IF(lstSections2 = True, true, false)}" >
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
    <apex:pageBlockSection title="Select Bundle" >
    <apex:pageBlockSectionItem >
        <apex:actionRegion >
                    <apex:pageBlockTable value="{!QL}" var="Q">
                        <apex:column headerValue="Select Bundle">
                        <apex:inputField value="{!Q.Bundle__c}">
                            <apex:actionSupport event="onchange" rerender="relatedBundleInfo" action="{!retrieveBundleInfo}" immediate="false" oncomplete="ExtraTDhide();"/>
            <apex:pageblockSection id="relatedBundleInfo">
                <apex:repeat value="{!BundleWrapperList}" var="BWrapper" >
                    <apex:pageBlockTable value="{!BWrapper.bundlePQList}" var="B">
                        <apex:column >
                            <apex:pageblockTable value="{!B.Product_Quantities__r}" var="bwithp">
                            <apex:column headerValue="Bundle Name">
                                <apex:outputField value="{!bwithp.Bundle__c}"/>
                            <apex:column headerValue="Product Name">
                                <apex:outputField value="{!bwithp.Product__c}"/>
                            <apex:column headerValue="Quantity">
                                <apex:inputfield value="{!bwithp.Quantity__c}"/>
                            <apex:column headerValue="Part Number">
                            <apex:pageBlockSection >
                                <apex:outputText value="{!bwithp.Product__r.ProductCode}" label="Part Number :"/>
                                <apex:outputText value="{!bwithp.Product__r.Description}" label="Description :"/>
                                <apex:outputText value="{!ListPrice}" label="List Price :"/>
                                <apex:outputText value="{!ListPrice}" label="Sale Price :"/>

Apex Class method :

public class AddGroupForQuoteController{

public boolean lstSections2{get;set;}
public Quote_Bundle_Product__c QBP{get;set;}
public List<Bundle__c> BundleWithPQList{get;set;}
public Bundle__c bundle{get;set;}
public List<BundleWrapper> BundleWrapperList{get;set;}

public AddGroupForQuoteController(ApexPages.StandardController controller) {
     lstSections2 = false;
     QBP = new Quote_Bundle_Product__c();
     BundleWithPQList = new List<Bundle__c>();
     bundle = new Bundle__c();
     BundleWrapperList = new List<BundleWrapper>();

    public void addSection2() {
        lstSections2 = true;
        QBP = new Quote_Bundle_Product__c();

    public void retrieveBundleInfo() {
            bundle = [SELECT Id, (select Id, Name, Product__c, Product__r.ProductCode, Product__r.Description, Quantity__c, Bundle__c from Product_Quantities__r) FROM Bundle__c WHERE Id =: QBP.Bundle__c];
             if(BundleWithPQList.size() > 0) {
                for(Bundle__c b : BundleWithPQList){
                    BundleWrapperList = new List<BundleWrapper>();
                    BundleWrapperList.add(new BundleWrapper(BundleWithPQList));

public class BundleWrapper {
    public List<Bundle__c> bundlePQList { get; set; }

    public BundleWrapper(List<Bundle__c> bundlePQList) {
        this.bundlePQList = bundlePQList;

Since your code is incomplete it is tough to say...

What I can give you is an example based off of Accounts.

The gist is

  1. Select an Account, click add
  2. A section will be added with the Account and its contacts
  3. repeat and the next section will be added

Maybe use this as a starting point.


public class testAccountClass {

    public Account[] accList {get;set;}
    public opportunity o {get;set;} //only used to get the account lookup

    public testAccountClass(){
        accList = New Account[]{};
        o = New Opportunity();

    public void addAccount(){
        [Select Id, Name, (Select Id, firstName, lastname from contacts) From Account Where Id = :o.AccountId]


VF Page

<apex:page id="testAccountPage" controller="testAccountClass">
    <apex:inputField value="{!o.AccountId}" />
    <apex:commandButton value="Add Bundle" action="{!addAccount}" reRender="relatedBundleInfo"/>

    <apex:pageBlock id="relatedBundleInfo">
        <apex:repeat value="{!accList}" var="acc">
            <apex:pageBlockSection title="Select Account">
                    <apex:pageblockSection >
                        <apex:pageBlockTable value="{!acc.Contacts}" var="B">
                            <apex:column headerValue="Bundle Name">
                                <apex:inputField value="{!acc.Name}"/>

                            <apex:column headerValue="First Name">
                                <apex:inputField value="{!B.FirstName}"/>
                            <apex:column headerValue="Last Name">
                                <apex:inputField value="{!B.LastName}"/>

NOTE All this is rough, no error checking, etc so make sure you add that in.

The resultant output it

enter image description here

Hopefully that will give you an idea of where to go.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.