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
Isaac GomolkaIsaac Gomolka 

How to assign picklist option

Hi everyone, I need to use apex code to assign a picklist option value to a certain user's field. Basically im automatically creatinga  new user using apex, and so its automatically assigning a bunch of the fields. Some of those fields are picklists and are required to create a new User. So im wondering how to / whats the code for assigning a specific picklist option. Like how do I get that specific options ID or something. Thanks for the help!

For example, this is basically what I need to do, just don't know how.

newUser.LocaleSidKey = picklistName.picklistOption;
Best Answer chosen by Isaac Gomolka
Raj VakatiRaj Vakati
Do it like a string assignement 


newUser.LocaleSidKey ='PICKLIST VALUE ';

 

All Answers

Raj VakatiRaj Vakati
Do it like a string assignement 


newUser.LocaleSidKey ='PICKLIST VALUE ';

 
This was selected as the best answer
Isaac GomolkaIsaac Gomolka
Hi Raj V,

Thanks for the response. Is that actually how it's done? Because i tried doing that and assigning it as a string, but then when i tested it by printing it out on my visualforce page im working with, nothing showed up.

I would do this in my apex class:
newUser.localeSidKey = 'English (United States)';

and then this in my VF page:
<apex:outputField value="{!newUser.localeSidKey}"/>

and nothing would show up. Am i doing it wrong somehow? Thanks for the help, i really appreciate it!
Raj VakatiRaj Vakati
Can you give me complete code 
Isaac GomolkaIsaac Gomolka
I actually just figured it out! That does work, assigning it as a string, but yeah it wouldn't print out for me. But if i made a string variable and then did variable=string.valueof(newUser.localeSidKey) it would print out that variable working just fine! So idk why it doesnt like to print out the field itself. But im just glad it works. thanks for the help!!!