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
Eager-2-LearnEager-2-Learn 

Picklists - Is there a way to programmatically populate picklists?

Is there a way to programmatically populate picklists?

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Hi E2L,

 

You can create such picklists using the resources I linked out too. You would simply query the table and then populate a List of type SelectOption. The problem here would be using such a picklist in a standard page since it would be embedded in the layout within it's own iFrame, and therefore be inaccessible to the standard controller.

 

You could get it to work (presumably you want to save the value to one of the current records fields?) if you create a component with the selectList and it's own save button and embed that component into a page with a standard controller that matches the object type, and then insert that page into the layout. That is messy, but it may suit your needs.

 

Your other options are:

 

1. Create a completely custom visualforce page

2. Create a trigger on the "Picklist values object/table" that makes a web service call to an intermediate system that makes a web service call back into SFDC using the metadata api and updates the metadata for a picklist on the object of your choice depending on what's added to/changed/removed from the table.

 

Hope that helps,

Wes

All Answers

Eager-2-LearnEager-2-Learn

Thanks for the information and the reference book.  I checked out the TOC and it looks like a book worth getting.  The only thing about all the SFDC books is they never get you complely there if you know what I mean.  I hope to see a mac-daddy book one day like I use to be able to get back in the dBase III and dBase IV days 600+ pages and if the answer wasn't there you didn't need to do it! :)

 

Back to my original question; I should have been more specific.  I wanted to know if I could programmatically read a table (object) and populate a standard SFDC page, not a VF page.  Is there a way to do that? 

Shashikant SharmaShashikant Sharma

If your question is to read the picklist options from a picklist field for any table(object), then answer is Yes, For that use describe calls. If I did notget your question correctly then please provide me more information what exactly is your question.

Eager-2-LearnEager-2-Learn

My mind is thinking like Visual Basic Load even works where I wanted to read a table that conains a list of names, for example and when the page loads I read the table and populate the drop down box with the list of names.

 

But as I am thinking about this type of action in Salesforce--we do not have that type of functionality with a Standard Page or do we?

 

If the answer is no then I wanted to know if there is a way in apex to programmatically populate a picklist field with elements from a table object.  I want the users to be in control of what is in the picklist.  So I am thinking that I could put a custom button on a page that calls some class code that clears out the current list on the pickllist field then repopulates it with the list of name on the table object.  I would give the users a tab that would give them access to the table.  Or is there another way of doing this type of thing but remember I want to stay as far away as possible from replacing my standard pages with VF pages. 

WesNolte__cWesNolte__c

Hi E2L,

 

You can create such picklists using the resources I linked out too. You would simply query the table and then populate a List of type SelectOption. The problem here would be using such a picklist in a standard page since it would be embedded in the layout within it's own iFrame, and therefore be inaccessible to the standard controller.

 

You could get it to work (presumably you want to save the value to one of the current records fields?) if you create a component with the selectList and it's own save button and embed that component into a page with a standard controller that matches the object type, and then insert that page into the layout. That is messy, but it may suit your needs.

 

Your other options are:

 

1. Create a completely custom visualforce page

2. Create a trigger on the "Picklist values object/table" that makes a web service call to an intermediate system that makes a web service call back into SFDC using the metadata api and updates the metadata for a picklist on the object of your choice depending on what's added to/changed/removed from the table.

 

Hope that helps,

Wes

This was selected as the best answer
Eager-2-LearnEager-2-Learn

Your suggestions is a viable solution; however, to extreme and too much involved.  For now I will or the admin will have to maintain the picklist.  I will mark it as a solution since it sounds extremely feasible.

 

Thank you very much.

Mark MoggyMark Moggy
Hi Eager-2-Learn did you find a solution to this?


Please let me know because I would lile to populate a Product picklist using the ... can you guess? ... yes the Product table! And I dont want the client's users to have to use the clumsy Lookup fields - it's sooo 1980's!
Eager-2-LearnEager-2-Learn
Unfortunately the answer is no.  Didn't have time to dig - but didn't SF give us the ability to add/read picklists via API now?
 
Stamen StoychevStamen Stoychev
As of 2020, we are still not able to modify picklist values via REST... Unbeleivable