0

I am having a text field and a picklist field.I want that picklist options be updated everytime a new & unique value is filled in the text field.So ,the next time user wishes to create a new record,he has that option available to be selected.How can this be achieved?

3
  • 1
    Are you OK with the new text value not appearing in the picklist for the current instance of the page, but want it to appear the next time the page is displayed?
    – Keith C
    Commented Jul 29, 2016 at 9:01
  • 2
    So you want to update the metadata from Apex? Check out this Apex wrapper for Metadata API github.com/financialforcedev/apex-mdapi
    – AslamK
    Commented Jul 29, 2016 at 9:03
  • Yes @Keith that would be OK Commented Jul 29, 2016 at 9:34

1 Answer 1

1

As AslamK mentions in his comment, you can modify the picklist entries from Apex. However, this is a web service call, and (I assume) requires permissions that typical users won't have. (Also, unless you cut it down the amount of Apex code you are adding is very large.)

An alternative is to merge the picklist values you get from a getPicklistValues describe call for the field with the added values obtained using a group by aggregate query on the field. Use a set to remove duplicates and then turn that set into a list and sort to have the values in a defined order. You return the values from your controller as a list of SelectOption objects and present them via the apex:selectOptions tag.

Also check that "Strictly enforce picklist values" is not selected for the picklist field.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .