function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HoysalaHoysala 

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:form>
         <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:selectList> 
        </apex:actionSupport>
       
        <apex:pageBlockTable value="{!accList}" var="acc" rendered="{!accList.size >0}">
            <apex:column value="{!acc.name}"/>
            <apex:column value="{!acc.rating}"/>
            
            </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

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];
        
    }

}

Thanks
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">
        <thead>
            <tr class="slds-text-title_caps">
                <th scope="col">
                    <div class="slds-truncate" title="Account Name">Account Name</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Contact">Contact</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Opportunity">Opportunity</div>
                </th>
            </tr>
        </thead>
        <tbody>
            <aura:iteration items="{!v.AccountList}" var="acc" >      
                <tr>
                    <td data-label="Account Name">
                        <div class="slds-truncate" title="Cloudhub">{!acc.Name}</div>
                    </td>
                    <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}" />
                            </aura:iteration>
                        </ui:inputSelect>
                    </td>
                    <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}" />
                            </aura:iteration>
                        </ui:inputSelect>
                    </td>                          
                </tr>
            </aura:iteration>                
        </tbody>
    </table>    
</aura:component>


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();
                    console.log('res-->>>'+res);
                    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: " +
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }else{
                    console.log('Something went wrong, Please check with your admin');
                }
            });
            $A.enqueueAction(action);
        } catch(ex){
            console.log(ex);
        }  
    },
})

Class :
public class ShowAccounts {
  @AuraEnabled
    public static List<Account> getAllAccounts() {
        try{
            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) {
                system.debug('accList-->>'+accList);
                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