Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AccountController {
- public Contact con { get; set; }
- public String selectedaccountId { get; set; }
- public List<SelectOption> getListOfAccounts() {
- List<Account> AccountList = [select id,Name from Account] ;
- List<SelectOption> AccountOptionList = new List<SelectOption>();
- AccountOptionList .add(new SelectOption( ' ' ,'---Select---'));
- for(Account acc : AccountList )
- {
- AccountOptionList.add(new SelectOption(acc.id , acc.Name));
- }
- return AccountOptionList ;
- }
- public PageReference loadDetails(){
- con = [Select LastName, FirstName From Contact Where Id = :selectedaccountId ];
- return null;
- }
- }
- <apex:page controller="AccountController">
- <apex:form >
- <apex:pageBlock >
- <apex:pageBlockSection title="Select the Account" >
- <apex:OutputPanel >
- <apex:selectList value="{!selectedaccountId}" size="1" multiselect="false" >
- <apex:selectOptions value="{!ListOfAccounts}" />
- <apex:actionSupport event="onchange"
- action="{!loadDetails}"
- rerender="contactDetails"/>
- </apex:selectList>
- </apex:OutputPanel>
- </apex:pageBlockSection>
- <apex:pageBlockSection title="Details" columns="1" id="contactDetails">
- <apex:outputField value="{!con.firstname}"/>
- <apex:outputField value="{!con.lastname}"/>
- </apex:pageBlockSection>
- </apex:pageBlock>
- </apex:form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement