+ Start a Discussion
hacksawblade16hacksawblade16 

attach checkboxes to custom object field

can yanyone  tell me how can i display the fields of custom object on vf page along with checkboxex attached to each field.Can i use param and assign to for this??if yes can anyone show me an example

prakash_sfdcprakash_sfdc
Yes. You can do that.

If the field in the object is of Checkbox Datatype, you can use <apex:inputField> or <apex:outputField> for input and output resp. Else, if you want to show custom checkbox then you can use <apex:inputCheckbox>

E.g:
<apex:inputCheckbox value="{!checkboxValue}"/>

//Apex Code

public Boolean checkboxValue{get;set;}
hacksawblade16hacksawblade16
the fields are not of type checkbox.They are different fields.i want to attach a check box for each field so that the user can select any of those fields and the selected fields will be mapped to fields of another object .that's the intention of having a checkbox associated with these fields.
Ranu JainRanu Jain

Hi ,

 

I could not understand the proper requirement But the solution is in Wrapper class.

Create a wrapper class like 

 

public class Wrapper {
  boolean checkboxVar{get;set;}
  String fieldname ;
}

 

 

Make a list of type List<Wrapper> listOfWrapper;  and iterate this list on VF page like :

 

<apex:pageBlockTable  value = "{!listOfWrapper}" var = "object">
<apex:column >
<apex:inputCheckbox value="{!object.checkboxVar}" > </apex:inputCheckbox>
</apex:column>
<apex:column > 
<apex:outputText  value = {!object.fieldname}> </apex:inputText>
<apex:column > 
<apex:pageBlockTable>

 

Hence by the wrapper class you can bind the check box value to the field. 

If this could not help you please provide me proper requiremt ,Will provide you appropiate result.

 

 

hacksawblade16hacksawblade16
Thank you :)..that helped me.I have one more requirement. i need to display a list on visual force page in which the first record in the list is a lead object record and the next is the list of people object records.Every record in the list will have a radio button attached to it and the selected record should be passed to my controller.
Ranu JainRanu Jain
Here What is mean by "people object record". For what object this is reffered?
hacksawblade16hacksawblade16
people is nothing but contacts..that is a custom object...in my project leads are the prospects and contacts are the people..let me just tell what I'm trying to do. I'm basically converting the prospect(lead) into people(contact) and before converting i need to check if the prospect(lead) already exists as people(contact) or not to avoid duplicate records,For this purpose i use * prospect(lead) record first name soundex* to match with *people(contact) record first name soundex*.The result will be a list of matching people(contact)records which i need to display on the VF page. On the VF page i must display a list in which The prospect(lead) whom I'm trying to convert must be displayed as the first row of this list and second row onwards the matching people list will begin. Each row in the list will have a corresponding radio button. *first name * * last name company* radiobutton1) jack sparrow infosys-------:>(prospect) lead record radiobutton2) jack mathews salesforce----->matching people record based on first name of prospect(lead) record radiobutton3) jack fernandes IBM -------------->matching people(contact) record based on first name
hacksawblade16hacksawblade16

this is the format in which it must be on the Vf page    

 

 

                                 first name         last name      company
    radiobutton1)          jack                sparrow          infosys-------:>(prospect) lead record
    radiobutton2)          jack                mathews        salesforce----->matching people record based on first name of prospect(lead) record
    radiobutton3)          jack                fernandes       IBM -------------->matching people(contact) record based on first name

-                                       -

-                                       -

-                                       -

-                                       -

-radiobutton n)       record n

prakash_sfdcprakash_sfdc

Hi,

 

I  think Wrapper Class will help you to achieve this. Please get the basics of Wrapper Class.

 

I will try to give you the logic

 

class ParentWrapper{

//This class is used to show the Lead(Prospect) record

public List<ChildWrapper> peopleList{get;set;}

public Boolean radioButton{get;set;}

public Lead prospectRecord{get;set;}

}

 

class ChildWrapper{

public Contact singleContact{get;set;}

public Boolean radioButton{get;set;}

}

 

List<ParentWrapper> pList=new List<ParentWrapper>();

 

List<Lead> mainList=[SOQL];

for(Lead temp:mainList)

{

 

 List<Contact> conList=[SELECT FirstName,LastName WHERE FirstName LIKE temp.FirstName];

List<ChildWrapper> cList=new List<ChildWrapper>();

for(Contact c:conList)

{

ChildWrapper tempCW=new ChildWrapper();

tempCW.singleContact=c;

cList.add(tempCW);

}

ParentWrapper tempRecord=new ParentWrapper();

tempRecord.prospectRecord=temp;

tempRecord.peopleList=cList;

}

 

//VF Page

 

You can use nested repeat

 

<apex:repeat value={!pList} var="p">

<tr>

<td><apex:selectRadio/></td>

<td>FirstName</td>

<td>LastName</td>

</tr>

<apex:repeat value={!p.peopleList} var="c">

<tr>

<td><apex:selectRadio/></td>

<td>FirstName</td>

<td>LastName</td>

</tr>

</apex:repeat>

</apex:repeat>

 

 

I hope it helps. Please mark it as solution if  it solves your issue.