+ Start a Discussion

when i change picklist it has to display accounts of type picklist selected.

when i change picklist it has to display
   accounts of type picklist selected.
Vivek S 42Vivek S 42
Can you post the Question properly explaining in detail you are trying to ask. 
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Suraj,
Please check the below code:

vf page:
<apex:page StandardController="Account" extensions="SelectPicklistClass">
         <apex:pageblock >
        <apex:actionSupport action="{!DisplayRecords}" event="onchange">
        <apex:selectList id="Rating" value="{!selectedValue}" size="1" >
            <apex:selectOption itemValue="Hot" itemLabel="Hot"/>
            <apex:selectOption itemValue="Warm" itemLabel="Warm"/>
            <apex:selectOption itemValue="Cold" itemLabel="Cold"/>
        <apex:pageBlockTable value="{!accList}" var="acc" rendered="{!accList.size >0}">
            <apex:column value="{!acc.name}"/>
            <apex:column value="{!acc.rating}"/>

Apex Class:
public class SelectPicklistClass {
    public static String selectedValue{get;set;}
    public static List<Account> accList{get;set;}
    public SelectPicklistClass(ApexPages.StandardController stdCon)
        accList=new List<Account>();
    public static void DisplayRecords()
      accList=[select id,name,rating from Account where rating=:selectedValue];


Hope this will be useful.​​​​​​​
Ajay K DubediAjay K Dubedi
Hi Suraj,

Below Sample Code can fulfill your requirements, Hope this will work for you.

Component :

<aura:component controller="ShowAccounts" access="global">
    <aura:attribute name="AccountList" type="list[]" />
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">
            <tr class="slds-text-title_caps">
                <th scope="col">
                    <div class="slds-truncate" title="Account Name">Account Name</div>
                <th scope="col">
                    <div class="slds-truncate" title="Contact">Contact</div>
                <th scope="col">
                    <div class="slds-truncate" title="Opportunity">Opportunity</div>
            <aura:iteration items="{!v.AccountList}" var="acc" >      
                    <td data-label="Account Name">
                        <div class="slds-truncate" title="Cloudhub">{!acc.Name}</div>
                    <td data-label="Contact">                        
                        <ui:inputSelect class="slds-select" aura:id="contactID">
                            <ui:inputSelectOption text="" label="Please Select a contact" disabled="true" />
                            <aura:iteration items="{!acc.Contacts}" var="cont">
                                <ui:inputSelectOption text="{!cont.Id}" label="{!cont.Name}" />
                    <td data-label="Opportunity">                        
                        <ui:inputSelect class="slds-select" aura:id="opportunityID">
                            <ui:inputSelectOption text="" label="Please Select an Opportunity" disabled="true" />
                            <aura:iteration items="{!acc.Opportunities}" var="opp">
                                <ui:inputSelectOption text="{!opp.Id}" label="{!opp.Name}" />

controller :

    doInit : function(c, e, h) {
        h.doInit_Helper(c, e, h);

Helper :


    doInit_Helper : function(c, e, h) {
        try {
            var action = c.get("c.getAllAccounts");
            action.setCallback(this, function(response){
                var state = response.getState();
                if(state === 'SUCCESS'){
                    var res = response.getReturnValue();
                    if(res != null) {
                        c.set("v.AccountList", res);
                }else if (state === 'ERROR'){
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " +
                    } else {
                        console.log("Unknown error");
                    console.log('Something went wrong, Please check with your admin');
        } catch(ex){

Class :
public class ShowAccounts {
    public static List<Account> getAllAccounts() {
            List<Account> accList = new List<Account>();
            accList = [select id, Name,(Select Id, Name from contacts),(Select Id, Name From Opportunities) from Account LIMIT 1000];
            if(accList.size() > 0) {
                return accList;
        } catch(Exception ex) {
            system.debug('Exception Error');
        return null;

Please mark this as best answer if this solves your problem.

Thank you,
Ajay Dubedi