Here is the code for Getting related contact records as a inputCheckBox values for the selected Account in visualforce page.
Apex Class:
Output
Apex Class:
Visualforce Page
01 | <apex:page standardController= "Contact" extensions= "contactCheckbox" showheader= "false" > |
02 |
03 | <apex:form > |
04 | <center> |
05 | <br/ > |
06 | <br/ > |
07 | <apex:outputLabel value= "Account Name" > |
08 | |
09 | <apex:inputField value= "{!Contact.AccountId}" required= "false" id= "lid" > <br/ > <br/ > <br/ > |
10 | <apex:actionsupport event= "onchange" rerender= "check" / > |
11 | </apex:inputField > |
12 | |
13 | </apex:outputLabel > |
14 | <apex:outputPanel id= "check" > |
15 | <apex:outputLabel value= "Contacts:" rendered= "{!contact.AccountId!=null}" > |
16 | <apex:selectCheckboxes value= "{!selectedAccount}" > |
17 | <apex:selectOptions value= "{!items}" / > |
18 | </apex:selectCheckboxes > <br/ > |
19 | </apex:outputLabel > |
20 | </apex:outputPanel > |
21 | </center> |
22 | </apex:form > |
23 |
24 | </apex:page > |
Output
01
public
class
contactCheckbox
02
{
03
public
contact selectedAccount{
get
;set;}
04
05
public
contactCheckbox(ApexPages.StandardController stdCtrl) {
06
selectedAccount=
(Contact)stdCtrl.getRecord();
07
}
08
09
public
List
<SelectOption
>
getItems()
10
{
11
12
List
<Contact
>
cntList=
[
select
Name
from
Contact
where
AccountId=
:selectedAccount.AccountID];
13
List
<SelectOption
>
options
=
new
List
<SelectOption
>
();
14
15
for
(Contact
c:cntList
)
16
{
17
options.add(
new
SelectOption(c.Name,c.Name));
18
}
19
return
options;
20
}
21
22
23
}