You need to sign in to do that
Don't have an account?
Chitral Chadda
code explanation
vf page with list of accounts ..when particular accnt name is selected it gives the name of the contacts in that particular account.
page
<apex:page standardController="Account" extensions="contactExt" showHeader="true" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Name" for="accts"></apex:outputLabel>
<apex:selectList id="accts" value="{!selectedAcctId}" size="1" >
<apex:selectOptions value="{!accts}"/>
<apex:actionsupport event="onchange" action="{! getAccountContacts}" rerender="ContactDetail" />
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:outputPanel id="ContactDetail">
<apex:repeat value="{!acctContacts}" var="contact">
<p>{!contact.FirstName & ' ' & contact.LastName}</p>
</apex:repeat>
</apex:outputPanel>
</apex:form>
</apex:page>
controller:
public class contactExt{
public String selectedAcctId { get; set; }
public List<Contact> acctContacts {get;set;}
public contactExt(Apexpages.StandardController con){
}
public void getAccountContacts(){
acctContacts = [Select Id, FirstName, LastName from Contact where AccountId = :selectedAcctId];
}
public List<selectOption> getaccts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Account account : [SELECT Id, Name FROM Account]) {
options.add(new selectOption(account.id, account.Name));
}
return options;
}
}
whats is the use of :::
<apex:selectList id="accts" value="{!selectedAcctId}" size="1" >
taking id = "accts"and value="{! selectedAccId}" ..what is id and value holding
page
<apex:page standardController="Account" extensions="contactExt" showHeader="true" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Name" for="accts"></apex:outputLabel>
<apex:selectList id="accts" value="{!selectedAcctId}" size="1" >
<apex:selectOptions value="{!accts}"/>
<apex:actionsupport event="onchange" action="{! getAccountContacts}" rerender="ContactDetail" />
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:outputPanel id="ContactDetail">
<apex:repeat value="{!acctContacts}" var="contact">
<p>{!contact.FirstName & ' ' & contact.LastName}</p>
</apex:repeat>
</apex:outputPanel>
</apex:form>
</apex:page>
controller:
public class contactExt{
public String selectedAcctId { get; set; }
public List<Contact> acctContacts {get;set;}
public contactExt(Apexpages.StandardController con){
}
public void getAccountContacts(){
acctContacts = [Select Id, FirstName, LastName from Contact where AccountId = :selectedAcctId];
}
public List<selectOption> getaccts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Account account : [SELECT Id, Name FROM Account]) {
options.add(new selectOption(account.id, account.Name));
}
return options;
}
}
whats is the use of :::
<apex:selectList id="accts" value="{!selectedAcctId}" size="1" >
taking id = "accts"and value="{! selectedAccId}" ..what is id and value holding
we use value="{!selectedAcctId}" to store our selected value from the List.
Means the value which we selected from pick list that value stored in SelectedAcctId variable.
All Answers
Value is the controllers's variable whose value you want to access
we use value="{!selectedAcctId}" to store our selected value from the List.
Means the value which we selected from pick list that value stored in SelectedAcctId variable.
means in the vf page suppose we select accnt name abcd so it id is stored in SelectedAcctId and
it will loop inside theacctContacts based on that SelectedAcctId from the picklist .
public void getAccountContacts(){
acctContacts = [Select Id, FirstName, LastName from Contact where AccountId = :selectedAcctId];
}
<apex:selectList id="accts" value="{!selectedAcctId}" size="1" >
<apex:actionsupport event="onchange" action="{! getAccountContacts}" rerender="ContactDetail" />
it will go to getAccountContacts then ,
<apex:repeat value="{!acctContacts}" var="contact">
<p>{!contact.FirstName & ' ' & contact.LastName}</p>
</apex:repeat>
it will loop in acctContacts and for all the contact found for a particular id , it will save it to the list :
public List<Contact> acctContacts {get;set;}
nd we will print it thru
var="contact"
<p>{!contact.FirstName & ' ' & contact.LastName}</p>
is this the functioning?