I have two picklist fields Category__c and SubCust__c(dependent on Category__c field). How to display this field values in vf page as multiselect from a Apex Class.
Currently both multiselect are published as static using dynamic apex.
Need help how to display as dependent.
public List<SelectOption> getDept()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult departfield = Activity_Tracker__c.Category__c.getDescribe();
List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
for( Schema.PicklistEntry f : picklist){
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<SelectOption> getDept()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult departfield = Activity_Tracker__c.SubCust__c.getDescribe();
List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
for( Schema.PicklistEntry f : picklist){
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
Regards
Best Answer
Basically what you are asking about, it is called as dependent\controlling picklist fields, you need to specify on field definition level that second picklist is dependent and select values available for each values of controlling field.
So you may use either apex:inputField or apex:selectList. If you want to allow users to select several values at a time you may set multiselect="true"
UPD.
You have the same name for two methods, you need have different method names. You may use something like this
In the controller you may add more logic like this
UPD: You may still use your unaltered version of getDept() method as getContFieldOptions to retrieve option for controller field: