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
sai tejsai tej 

HOw to display records based on picklist selection in visual force lightining

Hi, How to display case records based on picklist slection using visualforce LIghting
I have 4 Picklist fields in case object, i have to display these 4 picklist fields in  visulaforce page and based on thsese picklist fileds selection need to display case records on page .this should be done  in visulaforce lighting.Please help me to complete it.i am new to salesforce :( help
@ M  Coder@ M Coder
hello sai , 

i havent understood  :"visulaforce lighting" , both are different visualforce pages and lightning components ,

iif you are looking to display the picklist value of an object in lightning experience please use this below link . 

http://www.sfdcmonkey.com/2016/12/05/how-to-fetch-picklist-value-from-sobject-and-set-in-uiinputselect/


note: please mark as best answer if i resolve your query 
 
sai tejsai tej
Hi @M coder,


Have 4picklist fields those pick lists have to display on page and based on picklist selection have to display records at down.

Please help me .
 
Mustafa JhabuawalaMustafa Jhabuawala
Hi,

This is how you can display the picklist values in visualforce page - 

There are two points you are mentioning here - 
1. To display the picklist value
2. Display records on selection of picklist

Solution for the first point -

Apex Class - 
public List<SelectOption> getPicklistData()
{
  List<SelectOption> options = new List<SelectOption>();
        
   Schema.DescribeFieldResult fieldResult =
 YOUR_OBJECT_NAME__c.FIELDNAME__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        
   for( Schema.PicklistEntry entry : ple)
   {
      options.add(new SelectOption(entry.getLabel(), entry.getValue()));
   }       
   return options;
}

Visualforce Page -
<apex:selectList id="countries" value="{!YOUR_OBJECT_Name__c.FIELDNAME__c}"
         size="1" required="true">
  <apex:selectOptions value="{!picklistData}"/>
</apex:selectList>

This is how your picklist can be displayed in Visualforce page.

Second point -

Can you please clarify more on this, which data should be displayed on the selction of any picklist value ?


Thanks,
Mustafa Jhabuawala
Technical Lead at Zen4orce (http://www.zen4orce.com)
sai aswinisai aswini
Hi ,Thanks For the reply ,

for product object i have 4 picklist fileds based on pick list selection product records should display . and it should be done in lighting not in classic:(

please provide contact to me @ sairamsfdc9@gmail.com

regards,
Mustafa JhabuawalaMustafa Jhabuawala
Hi,

Do you have any specific requirement for this, for example - 

Picklist values - P1, P2, P3, P4

On selection of P1 - Show field 1, field 2
On selection of P2 - Show field 3, field 4
On selection of P3 - Show field 5, field 6
On selection of P4 - Show field 7, field 8

Is this you want to do or something else ?

Thanks,
Mustafa Jhabuawala
Technical Lead at Zen4orce (http://www.zen4orce.com)
sai aswinisai aswini
:( No ,, could you please provid your contact  number.
Mustafa JhabuawalaMustafa Jhabuawala
Hi Sai,

Can you share a sample mock up screen. So that I can visualise it and provide you the solution for the same.

You can connect via Skype if needed - mustafa.j0052
Amol Salve 14Amol Salve 14
Hello Sai,

I had created one dependent picklist example.I will share small code with you please change field with your object field
<aura:component implements="flexipage:availableForAllPageTypes" controller="DependentController" access="global">
	<aura:attribute name="Country" type="String" access="global"/>
	<aura:attribute name="State" type="String" access="global"/>
	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
	<aura:handler name="change" value="{!v.Country}" action="{!c.chanegState}"/>
	<ui:inputSelect aura:id="CountryId" label="Country" value="{!v.Country}"/>
	<ui:inputSelect aura:id="StateId" label="State" value="{!v.State}"/>
</aura:component>


({

    doInit : function(cmp) {        
        var action = cmp.get("c.countriesList");
        action.setCallback(this, function(response) {
            if(cmp.isValid() && response.getState() === "SUCCESS") {
                var options = response.getReturnValue();
                var picklistOptions = [];
                for (i= 0; i < options.length ; i++)
                {
                    picklistOptions[i] = { label: options[i].Label, value: options[i].Value};
                }
                cmp.find("CountryId").set("v.options", picklistOptions);
            }
        });
        $A.enqueueAction(action);
    },

    chanegState: function (cmp) {
        var countryvalue = cmp.get("v.Country");
        var action2 = cmp.get("c.showStates");
        action2.setParams({ "countryvalue" : countryvalue });
        action2.setCallback(this, function(response) {
            if(cmp.isValid() && response.getState() === "SUCCESS") {
                var options = response.getReturnValue();
                var picklistOptions = [];
                for (i= 0; i < options.length ; i++)
                {
                    picklistOptions[i] = { label: options[i].Label, value: options[i].Value};
                }
                cmp.find("StateId").set("v.options", picklistOptions);
            }
        });
        $A.enqueueAction(action2);
    }
})
public class DependentController{
public List<selectOption> countriesList() { 

            List<selectOption> countriesList = new List<selectOption>();
            countriesList.add(new selectOption(' ','--Select--'));

            map<string,Countries__c> countryMap = Countries__c.getAll();
            List<string> countries = new List<string>();
            countries.addAll(countryMap.keySet());
            countries.sort();

            for(string country : countries){

                Countries__c c = countryMap.get(country);
                countriesList.add(new selectOption(c.CountryCode__c, c.Name));
            }

            return countriesList; 
        }

  public List<selectOption> showStates() { 
		
		List<selectOption> statesList = new List<selectOption>(); 
		Map<String, States__c> allstates = States__c.getAll();
		Map<string, States__c> states = new Map<string, States__c>();
		for(States__c state : allstates.values()) { 
			if (state.countryCode__c == fanCountry_Region) { 
				states.put(state.name, state); 
			} 
		}
		 if(fanCountry_Region.contains('United States') || fanCountry_Region.contains('Canada ') ){
			
			statesList = new List<selectOption>();
		 }else{
			
			for (String stateName : stateNames) {
                States__c state = states.get(stateName);
                statesList.add(new SelectOption(state.StateCode__c, state.Name));
            }
		 }
		 return statesList;
    }
}

Thank you
Amol Salve
Salesforce Developer​
Thejasvi AThejasvi A
Hi Sai,
Even I have the same requirement wherein I have to display all the records of object based on picklist values. Could you please post if you have found a solution.
situsitu
Hi, How to display  records based on picklist slection using visualforce 
I have 3 values in my picklist-- Account,Contact,Leads..I need to display the duplicate records of selected object..for example I have selected Contact then it should display Contact duplicate records and so on.. How to achieve this.. can someone help me out.
Thanks in advance!!
Vina BarbuddheVina Barbuddhe
public class searchpicklistrec {
    
    public list<selectoption> pickval{set;get;}
    public list<account> acclst{set;get;}
    public string str{set;get;}
    
    public searchpicklistrec(){
        pickval=new  list<selectoption>();
        selectoption obj1=new selectoption('sonu','1');
        pickval.add(obj1);
        selectoption obj2=new selectoption('monu','2');
        pickval.add(obj2);
        selectoption obj3=new selectoption('vinu','3');
        pickval.add(obj3);
        
        acclst=[select id,name,phone from account limit 5];
    }
    public void serachrec(){
        acclst=[select id,name,phone from account where name=:str];
    }

}
vf page...
<apex:page controller="searchpicklistrec">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockTable value="{!acclst}" var="ac">
                 <apex:column value="{!ac.id}"/>
                 <apex:column value="{!ac.name}"/>
                 <apex:column value="{!ac.phone}"/>
            </apex:pageBlockTable>
            <apex:selectList size="1" value="{!str}">
                <apex:selectOptions value="{!pickval}"/>
            </apex:selectList>
           
            <apex:commandButton action="{!serachrec}" value="search"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Vina BarbuddheVina Barbuddhe
its for vf page not for lightning