Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class AccountController {
  2.  
  3. public Contact con { get; set; }
  4. public String selectedaccountId { get; set; }
  5. public List<SelectOption> getListOfAccounts() {
  6. List<Account> AccountList = [select id,Name from Account] ;
  7. List<SelectOption> AccountOptionList = new List<SelectOption>();
  8. AccountOptionList .add(new SelectOption( ' ' ,'---Select---'));
  9.  
  10. for(Account acc : AccountList )
  11. {
  12. AccountOptionList.add(new SelectOption(acc.id , acc.Name));
  13. }
  14. return AccountOptionList ;
  15. }
  16.  
  17. public PageReference loadDetails(){
  18. con = [Select LastName, FirstName From Contact Where Id = :selectedaccountId ];
  19. return null;
  20. }
  21. }
  22.  
  23. <apex:page controller="AccountController">
  24. <apex:form >
  25. <apex:pageBlock >
  26. <apex:pageBlockSection title="Select the Account" >
  27. <apex:OutputPanel >
  28. <apex:selectList value="{!selectedaccountId}" size="1" multiselect="false" >
  29. <apex:selectOptions value="{!ListOfAccounts}" />
  30. <apex:actionSupport event="onchange"
  31. action="{!loadDetails}"
  32. rerender="contactDetails"/>
  33.  
  34. </apex:selectList>
  35. </apex:OutputPanel>
  36.  
  37. </apex:pageBlockSection>
  38. <apex:pageBlockSection title="Details" columns="1" id="contactDetails">
  39. <apex:outputField value="{!con.firstname}"/>
  40. <apex:outputField value="{!con.lastname}"/>
  41. </apex:pageBlockSection>
  42. </apex:pageBlock>
  43. </apex:form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement