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
gkreddygkreddy 

can I the picklist be loaded dynamically after clicking on the button?

Hello,
I have requirement to load the picklist dynamically after some button click using other input fields.
Is it possible in visualforce?

Thank you
Raj VakatiRaj Vakati
You can able to do it like below

 
public static List < String > getselectOptions(sObject objObject, string fld) {
  system.debug('objObject --->' + objObject);
  system.debug('fld --->' + fld);
  List < String > allOpts = new list < String > ();
  // Get the object type of the SObject.
  Schema.sObjectType objType = objObject.getSObjectType();
 
  // Describe the SObject using its object type.
  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
 
  // Get a map of fields for the SObject
  map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();
 
  // Get the list of picklist values for this field.
  list < Schema.PicklistEntry > values =
   fieldMap.get(fld).getDescribe().getPickListValues();
 
  // Add these values to the selectoption list.
  for (Schema.PicklistEntry a: values) {
   allOpts.add(a.getValue());
  }
  system.debug('allOpts ---->' + allOpts);
  allOpts.sort();
  return allOpts;
 }

Refer this links 

https://salesforce.stackexchange.com/questions/131363/load-picklist-value-dynamically-using-javascript

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

https://www.fluidogroup.com/dynamic-picklist-values-u%EF%BB%BFsing-metadata-api/

https://www.biswajeetsamal.com/blog/get-picklist-values-dynamically-in-lightning-component/
gkreddygkreddy
Thanks Raj for your reply.
I have special custom logic for picklist values that depend on other input text fields.

The picklist need to be loaded on button click. 

Can you send me a sample code for the above requirement?

Thanks again for all your inputs.