+ Start a Discussion
Sunny SohailSunny Sohail 

Automatically adding values to picklist upon user creation

Currently when we set up a new user we have to add their names to 2 different picklists. If I am creating a sales rep user we have to add his or her name to the "salesrep" picklist and if I am creating BDR user I have to add his or her name to the "BDR" picklist. Is there a way that these names are automatically added to the picklist upon a user creation?
Marty C.Marty C.
Hello, Sunny, Apex does not have a native way to edit picklist definitions. However, Andrew Fawcett did create an Apex wrapper for the Metadata API[1] which makes it possible for you to manipulate metadata such as picklist values in an Apex trigger. I recommend checking that out if you're committed to editing those picklists.

An alternative is to create a Visualforce page, to be used standalone or as a component on a standard page layout. This Visualforce page could allow users to edit a field value using a picklist, and populate that picklist using User records retrieved via SOQL.

[1]: Apex wrapper for the Metadata API (https://github.com/financialforcedev/apex-mdapi)