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
kamlesh_chauhankamlesh_chauhan 

how to use controlling field in visual force page?

Hi,

 

I have custom field "Speciality(picklist)" and "SubSpeciality(multiselect picklist)" in my Account object. Speciality is the controlling field for SubSpeciality. Subspeciality is changed based on the selection of Speciality.

 

It is working fine in standard page layout. But I want to use it in my VF page to create new Account record. I have used inputfield and it display the details of both speciality and subspeciality. but subspeciality is not changed on selection of speciality.

 

How can I change the subspeciality on selection of speciality field. Following are sample code of my page.

Please help..... 

 

 

          <apex:inputfield value="{!Account.Speciality__pc}"></apex:inputfield>
           <apex:inputfield value="{!Account.Subspecialty__pc}" />

 

Thanks in Advance.

 

Kamlesh Chauhan

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah

As of now, dependent fields are not supported in Visualforce. One of the ways to implement it in Visualforce is to use action Support and Controller.

 Basically on the controlling field have an actionSupport with event Onchange. In the controller change the available values of the second picklist based on the value selected and rerender it.

Hope this helps

All Answers

Rajesh ShahRajesh Shah

As of now, dependent fields are not supported in Visualforce. One of the ways to implement it in Visualforce is to use action Support and Controller.

 Basically on the controlling field have an actionSupport with event Onchange. In the controller change the available values of the second picklist based on the value selected and rerender it.

Hope this helps

This was selected as the best answer
kamlesh_chauhankamlesh_chauhan

Hi Rajesh,

 

Thanks for replying :smileyhappy:. I think it would be the only solution for us.

 

Is there any way to retrieve picklist values in the controller through SOQL? From which object we can get the picklist values? If we can not retrieve picklist values from salefroce itself, we have to manually pass all picklist values :smileysad:

 

Any Idea??

 

Thanks,

Kamlesh Chauhan

Rajesh ShahRajesh Shah

Retrieving picklist values is certainly possible. For eg, the below statement retrieves all the picklist values for the field Status of Case.

 

public List<Schema.PicklistEntry> fieldPicklistValues = Case.Status.getDescribe().getPicklistValues();

for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
// use pickList.getValue() to get the value

// Use pickList.getLabel() to get the Label

}

  However I don't think it is possible to retrieve dependency between the picklist values.

 

 

Message Edited by Rajesh Shah on 11-06-2009 02:00 PM
kamlesh_chauhankamlesh_chauhan

Thankyou very much Rajesh.

 

It will 100% solve our problem. :smileyhappy:

 

Regards,

 

Kamlesh Chauhan