-
-
Save jenishshingala/8452c8061cdecb7ebb33 to your computer and use it in GitHub Desktop.
Account picklist ,by clicking on account it displays the related contacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apex page:--- | |
<apex:page controller="picacc_con_cls" > | |
<apex:form > | |
<apex:pageBlock title="Account Name"> | |
Account Name | |
<apex:selectList value="{!selectedAccId}" size="1"> | |
<apex:selectOptions value="{!AccountNames}" /> | |
<apex:actionSupport event="onchange" reRender="conlist"/> | |
</apex:selectList> <br/> <br/> | |
<apex:outputPanel id="conlist"> | |
<apex:outputPanel rendered="{!ContactNames!=null && ContactNames.size>0}"> | |
<apex:outputLabel value="Related Contacts:"/> | |
<apex:pageBlockTable value="{!ContactNames}" var="cons"> | |
<apex:column value="{!cons.Name}"/> | |
<apex:column value="{!cons.Email}"/> | |
<apex:column value="{!cons.MobilePhone}"/> | |
</apex:pageBlockTable> | |
</apex:outputPanel> | |
</apex:outputPanel> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> | |
Apex Controller: | |
public class picacc_con_cls { | |
public String selectedAccId{get;set;} | |
public String selectedConId{get;set;} | |
public picacc_con_cls() | |
{ | |
} | |
public List<SelectOption> getAccountNames() { | |
List<SelectOption> accOptions= new List<SelectOption>(); | |
accOptions.add( new SelectOption('','--Select--')); | |
for( Account acc : [select Id,name from Account ] ) { | |
accOptions.add( new SelectOption(acc.Id,acc.name)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/ | |
} | |
return accOptions; | |
} | |
public List<Contact> getContactNames() { | |
if(selectedAccId!=Null && selectedAccId!=''){ | |
List<Contact> conlist = new List<contact>(); | |
conlist = [select id,Name,Email,MobilePhone,Accountid from contact where Accountid=:selectedAccId]; | |
return conlist; | |
} | |
return Null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment