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
Mahesh Dhara 9Mahesh Dhara 9 

Is Anything Wrong with My code when I am selecting check box that records are not added to the selectdCandidates List

Controller:

public class Position_Candidate_Records_AC {
    public Position__c position                 {set;get;}
    public List<Candidate__c> candidates        {set;get;} 
    public List<CandidateWraper> candidateList  {set;get;}
    public Integer counter                      {set;get;}  
           public Position_Candidate_Records_AC(ApexPages.StandardController controller){
                    position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
                    candidates=[Select id,Name,    Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
                    counter=0;
                    candidateList=new List<CandidateWraper>();
               for(Candidate__c c:candidates){
                      CandidateWraper cw=new CandidateWraper();
                      counter++;
                      cw.candidate=c;
                      cw.counterWrap=counter;
                      cw.isSelected=false;
                      candidateList.add(cw);
                   
               }
    }
          public PageReference addRow(){
                      Candidate__c c=new Candidate__c();
                      CandidateWraper cw=new CandidateWraper();
                      counter++;
                      cw.candidate=c;
                      cw.counterWrap=counter;
                      cw.isSelected=false;
                      candidateList.add(cw);
                      return null;
    }
          public PageReference removeRow(){
                      Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
                     
                       for(Integer i=0;i<candidateList.size();i++){
                               if(candidateList[i].counterWrap == param ){
                                         candidateList.remove(i);     
                                    }
                       }
              
                      counter--;
                      return null;
    }
      
    public PageReference deleteSelected(){
      List<Candidate__c> selectedCandidates=new list<Candidate__c>();
       for(CandidateWraper cw:candidateList){
          if(cw.isSelected==true){
              System.debug('hi');
             selectedCandidates.add(cw.candidate);
           }
     }
        if(!selectedCandidates.isEmpty()){
              delete selectedCandidates;
          
      }
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
        ApexPages.addMessage(myMsg);
        
        return null;
   }
    public PageReference saveAll(){
        List<Candidate__c> updateCandidateList=new List<Candidate__c>();
        if(!candidateList.isEmpty()){
            for(CandidateWraper cw:candidateList){
                updateCandidateList.add(cw.candidate);
            }
        }
            if(!updateCandidateList.isEmpty()){
                upsert updateCandidateList;
            }
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
          ApexPages.addMessage(myMsg);
        return null;
    }
    
Public class CandidateWraper{
        public Candidate__c candidate {set;get;}
        public Integer counterWrap    {set;get;}
        public boolean isSelected     {set;get;}
    }    
}










public class Position_Candidate_Records_AC {
    public Position__c position                 {set;get;}
    public List<Candidate__c> candidates        {set;get;} 
    public List<CandidateWraper> candidateList  {set;get;}
    public Integer counter                      {set;get;}  
           public Position_Candidate_Records_AC(ApexPages.StandardController controller){
                    position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
                    candidates=[Select id,Name,    Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
                    counter=0;
                    candidateList=new List<CandidateWraper>();
               for(Candidate__c c:candidates){
                      CandidateWraper cw=new CandidateWraper();
                      counter++;
                      cw.candidate=c;
                      cw.counterWrap=counter;
                      cw.isSelected=false;
                      candidateList.add(cw);
                   
               }
    }
          public PageReference addRow(){
                      Candidate__c c=new Candidate__c();
                      CandidateWraper cw=new CandidateWraper();
                      counter++;
                      cw.candidate=c;
                      cw.counterWrap=counter;
                      cw.isSelected=false;
                      candidateList.add(cw);
                      return null;
    }
          public PageReference removeRow(){
                      Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
                     
                       for(Integer i=0;i<candidateList.size();i++){
                               if(candidateList[i].counterWrap == param ){
                                         candidateList.remove(i);     
                                    }
                       }
              
                      counter--;
                      return null;
    }
      
    public PageReference deleteSelected(){
      List<Candidate__c> selectedCandidates=new list<Candidate__c>();
       for(CandidateWraper cw:candidateList){
          if(cw.isSelected==true){
              System.debug('hi');
             selectedCandidates.add(cw.candidate);
           }
     }
        if(!selectedCandidates.isEmpty()){
              delete selectedCandidates;
          
      }
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
        ApexPages.addMessage(myMsg);
        
        return null;
   }
    public PageReference saveAll(){
        List<Candidate__c> updateCandidateList=new List<Candidate__c>();
        if(!candidateList.isEmpty()){
            for(CandidateWraper cw:candidateList){
                updateCandidateList.add(cw.candidate);
            }
        }
            if(!updateCandidateList.isEmpty()){
                upsert updateCandidateList;
            }
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
          ApexPages.addMessage(myMsg);
        return null;
    }
    
Public class CandidateWraper{
        public Candidate__c candidate {set;get;}
        public Integer counterWrap    {set;get;}
        public boolean isSelected     {set;get;}
    }    
}



Vf Page

<apex:page standardController="Position__c" extensions="Position_Candidate_Records_AC" tabStyle="Account" sidebar="false" >
    <apex:sectionHeader title="Position" subtitle="{!Position__c.Name}"/>
    <apex:messages />
     <apex:form >
         <apex:pageBlock title="Position Details">
             
             <apex:pageBlockTable value="{!position}" var="p">
                  <apex:column headerValue="PositionName" value="{!p.Name}" />
                  <apex:column headerValue="Functional Area" value="{!p.Functional_Area__c}" />
                  <apex:column headerValue="Max Pay" value="{!p.Max_Pay__c}" />
                  <apex:column headerValue="Min Pay" value="{!p.Min_Pay__c}" />
             </apex:pageBlockTable>
         </apex:pageBlock>
         
         <apex:pageBlock title="Candidate Details" id="pb1">
             <apex:pageBlockButtons location="Top">
                   <apex:commandButton value="Save" action="{!saveAll}"/>
             </apex:pageBlockButtons>
             <apex:pageBlockSection>
             <apex:pageBlockTable value="{!candidateList}" var="c" id="pb1" >
                   
                    <apex:column headerValue="Action">
                        <apex:commandLink value="Remove" action="{!removeRow}" immediate="true" reRender="pb1">
                            <apex:param name="index" value="{!c.counterWrap}"/>  
                        </apex:commandLink>
                    </apex:column>
                 <apex:column headerValue="Check">
                         <apex:inputCheckbox value="{!c.isSelected}" id="InputId"/>
                    </apex:column>
                  <apex:column headerValue="Position"  >
                       <apex:inputField value="{!c.candidate.Positin__c}" />
                 </apex:column>
                 <apex:column headerValue="City">
                      <apex:inputField value="{!c.candidate.City__c}" />
                 </apex:column>
                  <apex:column headerValue="Country">
                       <apex:inputField value="{!c.candidate.Country__c}" />
                 </apex:column>
                  <apex:column headerValue="Email">
                       <apex:inputField value="{!c.candidate.Email__c}" />
                 </apex:column>
                  <apex:column headerValue="Exp">
                       <apex:inputField value="{!c.candidate.Exp__c}" />
                 </apex:column>
             </apex:pageBlockTable>
         </apex:pageBlockSection>     
             <apex:commandButton value="AddRow" action="{!addRow}" reRender="pb1" immediate="true" />
             <apex:commandButton value="DeleteSelected" action="{!deleteSelected}" immediate="true"/>
         </apex:pageBlock>
     </apex:form>
</apex:page>
Mahesh Dhara 9Mahesh Dhara 9
I copied controller class two times both are same can any one explain why select candidate records are not added to selectdCandidate list when i check the check box
Pavit SiddhuPavit Siddhu
Hello , Sample code for add row functionality for the same May be help you.
 
​public class addrowcontroller {
    public List<Account> allAccList = new List<Account>();
    public List<Account> deleteAccList = new List<Account>();
    
    public List<Account> getAccounts(){
        
        if(allAccList.size()==0){
        Account ac = new Account();
        allAccList.add(ac);
        return allAccList;
        }
        else
        return allAccList;
       
    }
    public void addAccount(){
        Account ac = new Account();
        allAccList.add(ac);
    }
    public void removeAccount(){
        Integer indexVal = Integer.valueof(system.currentpagereference().getparameters().get('index'));
        if(allAccList[indexVal - 1].Id != null)
        deleteAccList.add(allAccList[indexVal - 1]);
        allAccList.remove(indexVal - 1);            
    }    
public Pagereference save(){
        upsert allAccList;
        if(deleteAccList.size() > 0)
            delete deleteAccList;
             PageReference pageRef = ApexPages.currentPage();
             pageRef.setRedirect(true);
             return pageRef;
  
}    
    
}

 
Mahesh Dhara 9Mahesh Dhara 9
Is anything wrong with my code
check box state is not changing it is alwaycs showing false wheather it is enable also