[SalesForce] Is it Possible to Add Value to Picklist Field by Visualforce

My scenario : I am creating visualforce page for custom object. I have one Picklist field(say, city__c). If user choose ---other--- option from the picklist, I must enable a textbox and Add button. When user type some text and click on add button the value should appear on options of picklist without reloading the page. Then user can choose the option that he added to picklist and can save the record.

  1. I heard it is possible only by calling metadata api to add a value to picklist field. So anyone is there to show me How to call this metadata in vfp controller?
  2. Is it possible to call a metadata without reloading the page? Because when Add button is clicked I want to add that value instantly to picklist without reloading the page(like using actionsupport).

It would be very much helpful if I found the solution.

Best Answer

You can add picklist values in your controller class so you can create a custom picklist on your page and add values that you need there (Also from your real picklist field).

<apex:selectlist value="{!somevalue}" multiselect="false" size="1">
    <apex:selectoptions value="{!someCollection}"/>
</apex:selectlist>

And if you don't want the entire page to be reloaded you will need to use apex:actionRegion to only reload a part of your page.