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
stollmeyerastollmeyera 

Automatically checking a box in a pageblocktable for multiple records

I have setup a VF edit page to show all of the contacts related to the selected account in a pageblockTable.  On this page I have a checkbox built in to not be visible and to automatically be checked, like the below:

 

<apex:inputcheckbox value="{!c.Create_Profile__c}" selected="true" style="visbility:hidden"/>

What I want to happen is this aforementioned Create_Profile__c field to be unchekced initially.  However, once the user accesses this VF page it will automatically check the box upon save, without them having to consciously do this  Unfortunately this is not happening right now.  Even though I have added the attribute for "selected=true", it is not actually checking this box (side note: this same attribute works fine with a pageblockSection).

 

Can I not use the "selected" attribute on a inputcheckbox when using a pageblockTable?

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

You can check checkbox on the page load in the page block table. You will have to pass the true value by the property for the check boxes.

 

For the reference use the below code

 

-------- VF page--------

<apex:page controller="checkcontact">
<apex:form >
  <apex:pageBlock >
      <apex:pageBlockTable value="{!con}" var="conlist">
      <apex:column >
          <apex:facet name="header">   <apex:inputCheckbox value="{!cc}" /></apex:facet>
      <apex:inputCheckbox selected="true" value="{!cc}" />
      </apex:column>
      
      <apex:column >
          <apex:facet name="header">Name</apex:facet>
            {!conlist.name}
      </apex:column>
      
             <apex:column >
          <apex:facet name="header">Email</apex:facet>
            {!conlist.Email}
      </apex:column>
      
      
      </apex:pageBlockTable>
  
  
  </apex:pageBlock>
  </apex:form>
</apex:page>

----- Apex controller------

public class checkcontact
{
    public list<contact> con {get;set;}
    public boolean cc{get;set;}
    public checkcontact()
    {
        con=new list<contact>();
        cc=true;
        con=[select name,email from contact];
    }

}


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

You can check checkbox on the page load in the page block table. You will have to pass the true value by the property for the check boxes.

 

For the reference use the below code

 

-------- VF page--------

<apex:page controller="checkcontact">
<apex:form >
  <apex:pageBlock >
      <apex:pageBlockTable value="{!con}" var="conlist">
      <apex:column >
          <apex:facet name="header">   <apex:inputCheckbox value="{!cc}" /></apex:facet>
      <apex:inputCheckbox selected="true" value="{!cc}" />
      </apex:column>
      
      <apex:column >
          <apex:facet name="header">Name</apex:facet>
            {!conlist.name}
      </apex:column>
      
             <apex:column >
          <apex:facet name="header">Email</apex:facet>
            {!conlist.Email}
      </apex:column>
      
      
      </apex:pageBlockTable>
  
  
  </apex:pageBlock>
  </apex:form>
</apex:page>

----- Apex controller------

public class checkcontact
{
    public list<contact> con {get;set;}
    public boolean cc{get;set;}
    public checkcontact()
    {
        con=new list<contact>();
        cc=true;
        con=[select name,email from contact];
    }

}


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

 

This was selected as the best answer
stollmeyerastollmeyera

@S Jain

 

Your response did indeed help me get to the solution!  All I needed to do was add a simple line for "contact.Create_Profile__c = true;", which I derived from the class you shared.

 

Thank you for the reply!!!