I have created a VF page that select multiple records from child (Contingency__c) and add them to parent (Billing_Change_Form__c) related list. Everything work fine other than one issue. Upon selecting a checkbox, the list renders itself with the same records. Here are the screen shots: Without Clicking: enter image description here

When I select a record it show this: enter image description here

They are the same records but added 2 more times.

My visualforce code:

<apex:page showHeader="Fasle" standardController="Billing_Change_Form__c" extensions="test2">
    <apex:form >
    <apex:PageBlock id="counter">

                      <apex:commandButton value="Save" action="{!mySave}" onComplete="window.top.close();"/>   
                      <apex:commandButton value="Cancel" onclick="window.top.close();" immediate="true" action="{!closePopup}"/>  

            <apex:pageBlockTable value="{!show}" var="e" title="show">

            <apex:column >
                <apex:inputCheckbox value="{!e.check}"/>
    <apex:actionSupport event="onclick" action="{!inIt}"/>

                <apex:column value="{!e.con.Name}"/>
                <apex:column value="{!e.con.discovery_amount__c}"/>
                <apex:column value="{!e.con.billing_begins_date__c}"/>
                <apex:column value="{!e.con.report_description__c}"/>
                <apex:column value="{!e.con.contingency__c}"/>


Controller Extension:

public class test2 {
    public string lookup{get;set;}
    public list<conCase> caseList{get;set;}
    public boolean allbool{get;set;}
    public string inputValue{get;set;}
    public boolean bool{get;set;}
    public set<id> caseIds{get;set;}
    Billing_Change_form__c[] accID = [Select account__c from Billing_Change_Form__c where 
                                               id = :System.currentPagereference().getParameters().get('id')];
    ApexPages.StandardController controller;

    public test2(ApexPages.StandardController con){
        controller = con;
        caseList = new list<conCase>();
        bool = false;
        caseIds = new Set<id>();

    public void inIt(){
        List<Contingency__c> selectedCase = new list<Contingency__c>();
        lookUp = '';
        for(conCase conObj : caseList){
            if(conObj.check !=false){
                system.debug('conObj.con'+ conObj.con);
                lookUp += conObj.con.name + ', ';
                system.debug('lookup:'+ lookup);
        bool = true;

    public List<conCase> getShow(){
        for(Contingency__c coObj : [Select id, name,billing_type__c, report_description__c, discovery_amount__c,
                        billing_begins_date__c, contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
            where (VENDOR_INVOICE__r.Account_del__r.Id = :accID[0].Account__c) ])
            caseList.add(new conCase(coObj, allBool));
        return caseList;

    public PageReference mySave(){
        list<Contingency__c> updateSelectedCase = new list<Contingency__c>();
        id billId = ApexPages.currentPage().getparameters().get('id');
        System.debug('Bill ID is' + billID);
        for(Contingency__c co:[select id, name, bill_form__c from Contingency__c where id = :caseIds ]){
            co.bill_form__c = billId;
        update updateSelectedCase;
        return null;

       /* PageReference billPage =  ApexPages.currentPage();
        return billPage;*/

    public void closePopup(){
        bool = false;
    public void add(){
        bool = true;
       public class conCase{
        public contingency__c con{get;set;}
        public boolean check{get;set;}
        public conCase(contingency__c c, boolean boo){
            con = c;
            check = boo;           

You need to re-initialize your list

public List < conCase > getShow() {
    caseList = new list <conCase> (); // this is the fix
        for (Contingency__c coObj: [Select id, name, billing_type__c, report_description__c, discovery_amount__c,
                billing_begins_date__c, contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
                where(VENDOR_INVOICE__r.Account_del__r.Id =: accID[0].Account__c)
            ]) {
            caseList.add(new conCase(coObj, allBool));
    return caseList;
  • @Ajit Chakraborty Thank so much!! It worked!! ; however, now it is deselecting the checkbox that I select. So when I check the box, it renders and deselect the box that I checked. Jan 14 '19 at 21:59
  • You need to preserve that data between server communication using hidden variable Jan 14 '19 at 22:02
  • Any tips on how to do that? I am very new to development. this is my first class and page. Jan 14 '19 at 22:18

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.