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
Nagesh ENagesh E 

Select check box is working one table and not working in other table.

public class AccountProfileFormExtention {
   
   public List<Visit_Report__c> visitReports,visitReportsAdd;
   public Visit_Report__c vReports,vReportsAdd; 
   set <id> acc1;   
   public Boolean nextdisplay=true;
   public Boolean savedisplay=true;
   public List<vAccounts> accountBussPlanList {get; set;}
   public List<vAccountsWO> accountBussPlanListWO {get; set;}
   List<Account> selectedAccounts = new List<Account>();
   List<Opportunity> selectedContacts = new List<Opportunity>();
  
   public Boolean getNextdisplay(){return nextdisplay;}
   public Boolean getSavedisplay(){return savedisplay;}
   
   public AccountProfileFormExtention(ApexPages.StandardController controller) {
         visitReports=getvisitReports();
     }
  /* public Visit_Report__c getvisitReportsAdd() {
      if(vReportsAdd == null)
         vReportsAdd = new Visit_Report__c();
      return vReportsAdd;
   }*/
   
   public PageReference getSelected(){
     
      for(vAccountsWO cCon1 : getnewAcctWO()) {
           selectedAccounts.clear();
           if(cCon1.selected == true) {
                 selectedAccounts.add(cCon1.acc);
            }
        }   
     return null;
    } 
      
    public Pagereference onLoad()
    {
      try{
            if(accountBussPlanList == null) {
       String currentQuater = ThisQuater();
             accountBussPlanList = new List<vAccounts>();
            
             List<Account> acc = new List<Account>();
             acc1 = new set <id>(); 
             
             Profile p= [Select Name, Id From Profile  where Name like 'Clinical Specialist'];
             if(UserInfo.getProfileId() == p.id){
                TerritoryManagement__c t = [Select Id From TerritoryManagement__c  where ClinicalSpecialistId__c=: UserInfo.getUserId() and IsActive__c= true Limit 1];
                acc = [SELECT id from Account where Target_Account__c = true and TerritoryManagementId__c =: t.Id];
             } 
             else {
                TerritoryManagement__c t = [Select Id From TerritoryManagement__c  where TerritoryManagerId__c=: UserInfo.getUserId() and IsActive__c= true Limit 1]; 
                acc = [SELECT id from Account where Target_Account__c = true and TerritoryManagementId__c =: t.Id];
             }  
             for(Integer i=0;i<acc.size();i++) {
              acc1.add(acc[i].Id);
             }
                        
            if(acc.size()>0){
                 for(Opportunity accBusPlan : [SELECT id,Sales_Account__c,Name from Opportunity where Sales_Account__c in: acc and Name like : currentQuater  ]) 
               {  accountBussPlanList.add(new vAccounts(accBusPlan));
               acc1.remove(accBusPlan.Sales_Account__c);
               }
              
             }   
             else {
               nextdisplay=false;
          savedisplay=true;
             }               
             
            }  
      }
      catch(Exception e)
      {
        ApexPages.addMessages(e);
        nextdisplay=false;
        savedisplay=false;
      }         
      return null;
    } 
      
    public List<vAccounts> getnewAcct(){
          return accountBussPlanList;
    }
    
    public List<vAccountsWO> getnewAcctWO(){
            if(acc1 != null) {
            accountBussPlanListWO = new List<vAccountsWO>();
          
             for(Account accBusPlan : [SELECT id,Name from Account where Id in: acc1 ]) {
                          accountBussPlanListWO.add(new vAccountsWO(accBusPlan));
             }                  
           }           
       return accountBussPlanListWO;
    }
    
    public PageReference processSelected() {
  
   for(vAccounts cCon : getnewAcct()) {
           if(cCon.selected == true) {
                selectedContacts.add(cCon.opp);
            }
        }
 
        for(vAccountsWO cCon1 : getnewAcctWO()) {
            
           if(cCon1.selected == true) {
                 selectedAccounts.add(cCon1.acc);
            }
        }     
        return  new PageReference('/apex/AccountPlanAdd');
    }
        
     public class vAccounts {
        public Opportunity opp {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public vAccounts(Opportunity o) {
            opp = o;
            selected = true;
        }
    }
    
      public class vAccountsWO {
        public Account acc {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public vAccountsWO(Account a) {
            acc = a;
            selected = true;
        }

 

 

VF Page:

 

<apex:page standardController="Visit_Report__c"
    extensions="AccountProfileFormExtention" action="{!onLoad}">
     <apex:pagemessages />
    <apex:form >
        <apex:pageBlock title="Accounts with Business Plans">

            <apex:pageBlockButtons >
                <apex:commandButton action="{!processSelected}" value="Next" rendered="{!nextdisplay}"/>
                <apex:commandButton action="{!saveAndAddVisitReports}" value="Create" rendered="{!savedisplay}"/>
            </apex:pageBlockButtons>
            
             <apex:pageBlockSection title="Accounts with Business Plans">
            <apex:pageBlockTable value="{!newAcct}" var="selectedAcc" rendered="{!(newAcct.size != 0)}">
                
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="checkAll(this,'checkedone')" />
                        </apex:facet>
                        
                        <apex:inputCheckbox value="{!selectedAcc.selected}" id="checkedone">
                        </apex:inputCheckbox>
                    </apex:column>
                    
                    <apex:column >
                    <apex:facet name="header">Account</apex:facet>
                    <apex:outputField value="{!selectedAcc.opp.Sales_Account__c}" />
                </apex:column>

                <apex:column >
                    <apex:facet name="header">Account Business Plan Name</apex:facet>
                    <apex:outputField value="{!selectedAcc.opp.Name}" />
                </apex:column>
                  
            </apex:pageBlockTable>
             <apex:outputText rendered="{!(newAcct.size = 0)}" value="There are no reocrds to display." />
            </apex:pageBlockSection>  
            
              
            <apex:pageBlockSection title="Accounts with out Business Plans">
           <apex:pageBlockTable value="{!newAcctWO}" var="selectedAccWO" rendered="{!(newAcctWO.size != 0)}">
                                          
           <apex:column >
                        <apex:facet name="header">
                            
                        </apex:facet>
                       <apex:inputCheckbox value="{!selectedAccWO.selected}" id="checkeSec">
                       
                        </apex:inputCheckbox>
                    </apex:column> 
                   
                 <apex:column >
                 <apex:facet name="header">Account</apex:facet>
                 <apex:outputField value="{!selectedAccWO.acc.Name}" />
                 </apex:column>
             
           </apex:pageBlockTable> 
            <apex:outputText rendered="{!(newAcctWO.size = 0)}" value="There are no reocrds to display." />
            </apex:pageBlockSection>
            
           
            
         </apex:pageBlock>
        <script type="text/javascript">
    function checkAll(cb,cbid)
        {
            var inputElem = document.getElementsByTagName("input");                     
            for(var i=0; i<inputElem.length; i++)
            {             
                 if(inputElem[i].id.indexOf(cbid)!=-1){                                        
                    inputElem[i].checked = cb.checked;
                }
            }
        }
</script>
        

    </apex:form>

</apex:page>


AmitSahuAmitSahu
<apex:page standardController="Visit_Report__c"
    extensions="AccountProfileFormExtention" action="{!onLoad}">
     <apex:pagemessages />
    <apex:form >
        <apex:pageBlock title="Accounts with Business Plans">

            <apex:pageBlockButtons >
                <apex:commandButton action="{!processSelected}" value="Next" rendered="{!nextdisplay}"/>
                <apex:commandButton action="{!saveAndAddVisitReports}" value="Create" rendered="{!savedisplay}"/>
            </apex:pageBlockButtons>
            
             <apex:pageBlockSection title="Accounts with Business Plans">
            <apex:pageBlockTable value="{!newAcct}" var="selectedAcc" rendered="{!(newAcct.size != 0)}">
                
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="checkAll(this,'checkedone')" />
                        </apex:facet>
                        
                        <apex:inputCheckbox value="{!selectedAcc.selected}" id="checkedone">
                        </apex:inputCheckbox>
                    </apex:column>
                    
                    <apex:column >
                    <apex:facet name="header">Account</apex:facet>
                    <apex:outputField value="{!selectedAcc.opp.Sales_Account__c}" />
                </apex:column>

                <apex:column >
                    <apex:facet name="header">Account Business Plan Name</apex:facet>
                    <apex:outputField value="{!selectedAcc.opp.Name}" />
                </apex:column>
                  
            </apex:pageBlockTable>
             <apex:outputText rendered="{!(newAcct.size = 0)}" value="There are no reocrds to display." />
            </apex:pageBlockSection>  
            
              
            <apex:pageBlockSection title="Accounts with out Business Plans">
           <apex:pageBlockTable value="{!newAcctWO}" var="selectedAccWO" rendered="{!(newAcctWO.size != 0)}">
                                          
           <apex:column >
                        <apex:facet name="header">
                             <apex:inputCheckbox onclick="checkAll(this,'checkeSec')" />
                        </apex:facet>
                       <apex:inputCheckbox value="{!selectedAccWO.selected}" id="checkeSec">
                       
                        </apex:inputCheckbox>
                    </apex:column> 
                   
                 <apex:column >
                 <apex:facet name="header">Account</apex:facet>
                 <apex:outputField value="{!selectedAccWO.acc.Name}" />
                 </apex:column>
             
           </apex:pageBlockTable> 
            <apex:outputText rendered="{!(newAcctWO.size = 0)}" value="There are no reocrds to display." />
            </apex:pageBlockSection>
            
           
            
         </apex:pageBlock>
        <script type="text/javascript">
    function checkAll(cb,cbid)
        {
            var inputElem = document.getElementsByTagName("input");                     
            for(var i=0; i<inputElem.length; i++)
            {             
                 if(inputElem[i].id.indexOf(cbid)!=-1){                                        
                    inputElem[i].checked = cb.checked;
                }
            }
        }
</script>
        

    </apex:form>

</apex:page>

 The line was missing iguess...

Nagesh ENagesh E

Thanks for response,That is not the issue, because when I am selecting manually each and every record it was deselecting(I put default selected). for testing purpose.