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
abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com 

Is there any way to send some selected checboxes checked in apex:checkbox

 <apex:selectcheckboxes value="{!certificates}" layout="pageDirection"  onchange="Acfunc();" >
                    <apex:selectOptions value="{!options }"/>    
                </apex:selectcheckboxes><br />

 

Is there any way to send some of the selected checkboxes checked  from inside the controller so that they seem  checked by default ...??

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Insert one New Line below line which you have given for option.add.

 

 

options.add(new SelectOption(CertInst.id,CertInst.name+'('+pop+')'));
certificates.add(CertInst.id);

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

All Answers

hitesh90hitesh90

Hi Abhishek,

 

Yes, you can set certificates = true; in your controller as per your requirement. so it will be checked by default in your VF page.

 

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com
  options.add(new SelectOption(CertInst.id,CertInst.name+'('+pop+')'));  

 

Its basically the options that is getting iterated so if u can put some coding help in putting those checkboxes selected in VF

 

certificates is just sending the values selected back to the controller or how is possible through certificates ...??

 

Thanks

hitesh90hitesh90

please share your full class code. i will explain it.

abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com
public class Tosearch {
    
    public List<Certificate__c> Cert {get;set;}
    public List<SelectOption> options {get;set;}
    public list<String> certificates {get;set;}
    public List<Contact> Q {get;set;}
    public List<Contact> I {get;set;}
    public list<Certificate__c> Certi = new list<Certificate__c>();
     public list<Certificate__c> Certi2 = new list<Certificate__c>();
    public List<Qualification__c> Cont=new List<Qualification__c>();
    public List<Qualification__c> Cont2=new List<Qualification__c>();
    
    public pagereference onload()
    {
        Cert=[Select c.Name From Certificate__c c];
        
        options = new List<SelectOption>();
        Cont=[Select QualificationType__c, QualificationStatus__c, QualificationValidity__c From Qualification__c where QualificationValidity__c='Geldig'];
        Certi = [
            SELECT 
                c.Id,
                c.name,
                (
                    SELECT Id
                    FROM Qualifications__r
                    WHERE QualificationValidity__c = 'Geldig'
                )
            FROM Certificate__c c
        ];
        system.debug('---certificates'+certificates );
        system.debug('Test');
        map<id,Integer> str= new map<id,Integer>(); 
        list<Integer> Int1= new list<Integer>();
        list<Integer> Int2= new list<Integer>();
        map<id,Integer> str2= new map<id,Integer>();
        list<id> lstid= new list<id>();
        list<Integer> lstint= new list<Integer>();
        map<list<id>,list<Integer>> str3= new map<list<id>,list<Integer>>();
        //system.debug('certificates.size()'+certificates.size());
        
        if(certificates.size()==0)
        { 
            system.debug('Testin');
               
             system.debug('Testin');     
            for(Certificate__c cc:Certi)
                {   Integer count=0;
                    for(Qualification__c qq: Cont)
                    {            
                        if(cc.id==qq.QualificationType__c)
                        {
                           count++ ; 
                        }
                    }
                  str.put(cc.id,count);
                }
                   
           
            
           
            system.debug('--str.keyset()'+str.keyset()); 
            
            for(String id1:str.keyset())
            {
              system.debug('--str.get(id1)'+str.get(id1)); 
              Int1.add(str.get(id1));
            }
            system.debug('--Int1'+Int1);
            Int1.sort();
            system.debug('--Int1'+Int1);
            
           
            for(Integer i=(Int1.size()-1);i>=0;i--)
            {
                Int2.add(Int1[i]);
            }
            system.debug('---Int2'+Int2);
                        
            system.debug('Test23');
            
            for(Integer Int3:Int2)
                {
                    system.debug('--Int3'+Int3);
                    for(String Str11:str.keyset())
                    {                        
                    //for(Integer InstInt:str.get(Str11))
                    //{ 
                        system.debug('--Str11'+Str11);
                        if(str.get(Str11)==Int3)
                        {
                            if(str2.containskey(Str11))
                            {
                            }
                            else
                            {
                                lstid.add(Str11);
                                lstint.add(Int3);
                                system.debug('--Str112'+Str11);
                                system.debug('--Int32'+Int3);
                                system.debug('----Newstr2'+str2);
                                str2.put(Str11,Int3);
                            }
                        }
                    //}          
                    }            
                }
            str3.put(lstid,lstint);
            system.debug('--lstid'+lstid);
            system.debug('--lstint'+lstint);
            system.debug('--str2'+str2);
            system.debug('--str3'+str3);
            
                         
                //for(String Str1:lstid)
                for(Integer e=0;e<lstid.size();e++)
                {
                   
                    for(Certificate__c CertInst: Cert)
                     {  
                    
                        if(CertInst.id==lstid[e])
                        {
                            Integer pop=0;
                            pop=lstint[e];
                            
                            //Integer pop=str.get(Str1);
                                if(pop>0)
                                options.add(new SelectOption(CertInst.id,CertInst.name+'('+pop+')'));                            
                        }
                    }    
                }   
       
        }
        
        else
        {
             Certi2 = [
                        SELECT 
                            c.Id,
                            c.name,
                            (
                                SELECT Id
                                FROM Qualifications__r
                                WHERE QualificationValidity__c = 'Geldig' And Not In :certificates
                            )
                        FROM Certificate__c c
                        ];
             Cont2=[Select QualificationType__c, QualificationStatus__c, QualificationValidity__c From Qualification__c where QualificationValidity__c='Geldig'];                           
             map<id,Integer> str4= new map<id,Integer>();   
             
               for(Certificate__c cc:Certi2)
                    {   Integer count=0;
                        for(Qualification__c qq: Cont2)
                        {            
                            if(cc.id==qq.QualificationType__c)
                            {
                               count++ ; 
                            }
                        }
                      str4.put(cc.id,count);
                    }                              
        }
      return null;
    
    }
    
    
    
    public pagereference search() {
         
   
    
        Q  = new List<Contact>();
        I = [
            SELECT
                Id,
                Name,
                EmployeeStarted__c,
                Employee_Passport_Number__c,
                Contact_Drivers_Licences__c,
                Employee_High_Pressure__c,
                Employee_Pressure_Vacuum__c,
                Employee_Safety__c,
                Employee_Medical__c,
                Employee_Other__c,
                (
                    SELECT Id
                    FROM Qualifications__r
                    WHERE QualificationValidity__c= 'Geldig'
                        AND QualificationType__c = :certificates
                )
            FROM Contact c
            WHERE (EmployeeStatus__c = 'Active'
                OR EmployeeStatus__c = 'In termination')  ORDER BY Name  ASC
        ];
        
        for (Contact c:I) {
            if (certificates.size() == c.Qualifications__r.size()) {
                Q.add(c);
            }
        }
        onload();
        return null;
    }
  
    public Tosearch() {
        Q = new List<Contact>();
        certificates = new list<string>();
        
        Q = [
            SELECT
                Id,
                Name,
                EmployeeStarted__c,
                Employee_Passport_Number__c,
                Contact_Drivers_Licences__c,
                Employee_High_Pressure__c,
                Employee_Pressure_Vacuum__c,
                Employee_Safety__c,
                Employee_Medical__c,
                Employee_Other__c
            FROM Contact c
            WHERE (EmployeeStatus__c = 'Active'
                OR EmployeeStatus__c = 'In termination')  ORDER BY Name  ASC
        ];
        
    }
    
}

 Here it is

hitesh90hitesh90

Insert one New Line below line which you have given for option.add.

 

 

options.add(new SelectOption(CertInst.id,CertInst.name+'('+pop+')'));
certificates.add(CertInst.id);

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

This was selected as the best answer