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
Ritika ShoucheRitika Shouche 

Adding custom Checkboxes in ApexPageblockTable Column

Hi,

I have three Objects to Deal with - User (Portal user), Contact and CustomObject.
CustomObject is Child of Contact.

Considering Three Checkbox fields on Custom Child Object I want to display Checkbox True or False in front of user record on VIualforce Page table.
 
//This gives me Logged in users ID and ContactID on his user record
userList  = new List<User>();
    User usr = [Select Id, contactId from User WHERE ID ='XXXyyyyyyyZZZZ' ];
     
//This gives me name of Account of Contact of Logged in User
con = [Select id,Name,AccountId,Account.Name,Phone__c ,Email__c FROM  Contact WHERE ID =: usr.ContactId];
   
//This gives me List of all Contacts for that Account also FIelds on Custom CHild Object of Contact which we need to use for Checkbox Display
contactInfo = [Select id,Name, (SELECT ID ,Active__c,Support__c FROM CustomObject__r)from Contact WHERE AccountId =: con.accountId];
    
//This gives List of Users for those Contacts       
userinfolist = [Select Id,Name,ContactId,Contact.Name,Email,CompanyName,Phone from User Where IsActive = true AND Profile.Name =: Label.SupportUser AND ContactId IN: contactInfo];
    
}

With above information, I can display Name of User, Email and Phone using List "userinfolist ". Now I want to add A column with a checkbox, where if User's Contact record has CustomCHild Object record created and IF Active__c and Support__c field on that child record are True then Display true on userinfolist.

 
Best Answer chosen by Ritika Shouche
Akshit HuriaAkshit Huria
Hi Ritika
public class mainClass
{
    Public List<wclass> allusr {get;set;}
    public List<user> cbo;
}

//onload 
public t2()
    {

//This gives me Logged in users ID and ContactID on his user record
userList  = new List<User>();
    User usr = [Select Id, contactId from User WHERE ID ='XXXyyyyyyyZZZZ' ];
     
//This gives me name of Account of Contact of Logged in User
con = [Select id,Name,AccountId,Account.Name,Phone__c ,Email__c FROM  Contact WHERE ID =: usr.ContactId];
   
//This gives me List of all Contacts for that Account also FIelds on Custom CHild Object of Contact which we need to use for Checkbox Display
contactInfo = [Select id,Name, (SELECT ID ,Active__c,Support__c FROM CustomObject__r)from Contact WHERE AccountId =: con.accountId];
    
//This gives List of Users for those Contacts       
userinfolist = [Select Id,Name,ContactId,Contact.Name,Email,CompanyName,Phone, Active__c, Support__c from User Where IsActive = true AND Profile.Name =: Label.SupportUser AND ContactId IN: contactInfo];
    


        usr = new List<user>();
        cc = new List<wclass>();
        for(user varName :userinfolist )
        {
            if(varName.Active__c == true && varName.Support__c == true)
{
                 allusr.add(new wclass(varName, true));
              }
              else
               {
                allusr.add(new wclass(varName, false));
               }
        }
    }

//Wrapper Class
public class wclass
    {
        public user  infoList{get; set;}
        public Boolean selected{get; set;}
       
 public wclass(user  uil, Boolean b)
        {
            infoList=uil;
            selected = b;
        }
    }



-------------------vf page------------------

//use User's "allusr list" in the vf page instead of userInfoList

Thank You
Akshit

All Answers

Akshit HuriaAkshit Huria
Hi Ritika
public class mainClass
{
    Public List<wclass> allusr {get;set;}
    public List<user> cbo;
}

//onload 
public t2()
    {

//This gives me Logged in users ID and ContactID on his user record
userList  = new List<User>();
    User usr = [Select Id, contactId from User WHERE ID ='XXXyyyyyyyZZZZ' ];
     
//This gives me name of Account of Contact of Logged in User
con = [Select id,Name,AccountId,Account.Name,Phone__c ,Email__c FROM  Contact WHERE ID =: usr.ContactId];
   
//This gives me List of all Contacts for that Account also FIelds on Custom CHild Object of Contact which we need to use for Checkbox Display
contactInfo = [Select id,Name, (SELECT ID ,Active__c,Support__c FROM CustomObject__r)from Contact WHERE AccountId =: con.accountId];
    
//This gives List of Users for those Contacts       
userinfolist = [Select Id,Name,ContactId,Contact.Name,Email,CompanyName,Phone, Active__c, Support__c from User Where IsActive = true AND Profile.Name =: Label.SupportUser AND ContactId IN: contactInfo];
    


        usr = new List<user>();
        cc = new List<wclass>();
        for(user varName :userinfolist )
        {
            if(varName.Active__c == true && varName.Support__c == true)
{
                 allusr.add(new wclass(varName, true));
              }
              else
               {
                allusr.add(new wclass(varName, false));
               }
        }
    }

//Wrapper Class
public class wclass
    {
        public user  infoList{get; set;}
        public Boolean selected{get; set;}
       
 public wclass(user  uil, Boolean b)
        {
            infoList=uil;
            selected = b;
        }
    }



-------------------vf page------------------

//use User's "allusr list" in the vf page instead of userInfoList

Thank You
Akshit
This was selected as the best answer
Akshit HuriaAkshit Huria
Hi Ritika
If this answer is helps you please let me know

Thank You
Akshit
Ritika ShoucheRitika Shouche
Thank you Akshit.With some tweaks It Works exactly how I want it to.Thanks again.