+ Start a Discussion

bind checkbox with records in pageblocktable

I have created a table with pageblocktable to display a custom object fields on  VF page, I have created a column of checkbox in the same table. I want to select the record through these checkbox and want to insert the selected record in another object having same fiields.

karunakarreddy bade 8karunakarreddy bade 8

I think this documentation is worth reading through for a better understanding 


Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hipe that will help u
This is a perfect scenario where a wrapper class can be used.

Please let us know if this will help u
Hi Sarisfdc,
I think here wrapper class i snot required .Wrapper class wil help you incase you want any check box field programatically .
As you have not mentioned your object names and field names in above post .

Try with belew code and replace and modify as per your need .
<apex:page controller="CreateSeletedRecord" >
	 <apex:form id="frm">
	     <apex:pageBlockTable value="{!recList}" var="rec">
		    <apex:column value="{rec.CheckBox__c}"/>
		    <apex:column value="{rec.Name__c}"/>
		 <apex:commandButton value="createRec" action="{!doCreateRec}" />
public class CreateSeletedRecord{
  public List<ObjectFrom__c> objFromList{get;set;}
  public CreateSeletedRecord(){
       objFromList=new List<ObjectFrom__c>();
      objFromList=[SELECT id,Name__c,CheckBox__c FROM ObjectFrom__c WHERE CheckBox__c != true];
  public void doCreateRec(){
      List<ObjectFrom__c> objfrmList=new List<ObjectFrom__c>();
       List<ObjectTo__c> objToList=new List<ObjectTo__c>();
     for(ObjectFrom__c objfrm : objFromList){
	    if(objFrm.CheckBox__c ==true){
		   ObjectTo__c objTo=new ObjectTo__c();
            objTo.Name__c=	objfrm.Name__c;
      update objfrmList;
	   insert objToList;
Add additional fields in the code .
ObjectTo__c you can replace with your object which you need to create .
ObjectFrom__c replace with your object which want to display .
If you want like once you have created selected record in teh second object then you can update the checkbox in first object and filter in the query as in the post .
Any issue please let  us know so that we can help !!
thanks Manoj,

In your code, what is recList (value used in pageblock table). How I will mark the checkbox true on my VF page.
Apex:column return the value in outut form(non editable). Please suggest.

Suraj Tripathi 47Suraj Tripathi 47
Hi Sarisfdc,

You can add checkbox in your page using below line of code.
<apex:inputCheckbox value="{!c.yourValue}" />

If you find your Solution then mark this as the best answer.

Thank you!

Suraj Tripathi