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
SarisfdcSarisfdc 

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.

Thanks!
karunakarreddy bade 8karunakarreddy bade 8
hi,


I think this documentation is worth reading through for a better understanding 
(http://salesforce.stackexchange.com/questions/41092/manage-state-for-apexinputcheckbox-on-visualforce-page-when-adding-dynamic-apex)


Thanks
B.karunakar

 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hipe that will help u
https://developer.salesforce.com/page/Wrapper_Class
This is a perfect scenario where a wrapper class can be used.

Please let us know if this will help u
ManojjenaManojjena
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:pageBlockTable>
		 <apex:commandButton value="createRec" action="{!doCreateRec}" />
	 </apex:form>
</apex:Page>
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;
            objToList.add(objTo);	
            objfrmList.add(objFrm);
		
		}
	 }
     if(!objfrmList.isEmpty()){
      update objfrmList;
      }
	 if(!objToList.isEmpty()){
	   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
 
SarisfdcSarisfdc
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.

Thanks!
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!

Regards,
Suraj Tripathi