+ Start a Discussion
DannyK89DannyK89 

Multi-Select Pick List Fields

Is there a way to add more selections into a multi-select pick list using apex? If there is a code sample or a link to some documentation would help. Thanks. 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Yes, you can do that.

 

E.g.

 

 

MyObj__c obj=new MyObj__c(Name='Fake');
obj.pick__c=obj.Name;

 

Salesforce will also allow you to specify values that aren't in the picklist configuration - they get stored but can't be reported/filtered on.

 

All Answers

bob_buzzardbob_buzzard

Are you looking to add more elements to the picklist configuration?  I.e. mimic what you would do in the admin page?

 

If so, I think you're out of luck.  We've struggled with this on a number of projects and have yet to come up with anything approaching a solution.  If not, can you explain a bit more.

DannyK89DannyK89

I would like to add more values to the list of values in the pick list. 

bob_buzzardbob_buzzard

Sorry - I'm still not quite understanding what you are trying to do.

 

Do you want to add more values so that when the multi-select picklist is displayed on a standard page (for example), or are you trying to poplate a multi-select picklist field programmatically?

DannyK89DannyK89

Sorry I'm really bad at explaining things. I want to populate a multi-select picklist field programmtically.

bob_buzzardbob_buzzard

You can set the values into the field as text separated by the semicolon character.

 

e.g.

 

 

MyObj.myfield='value1;value2;value3';

 

 

DannyK89DannyK89

Ok, so lets say I have an Object called "Obj" with a multi-select picklist field called "pick" and I want to populate "pick" with "MyObj.name" when a MyObj record is created. Is that possible. 

bob_buzzardbob_buzzard

Yes, you can do that.

 

E.g.

 

 

MyObj__c obj=new MyObj__c(Name='Fake');
obj.pick__c=obj.Name;

 

Salesforce will also allow you to specify values that aren't in the picklist configuration - they get stored but can't be reported/filtered on.

 

This was selected as the best answer
DannyK89DannyK89

Thanks for the help

reatlimecoreatlimeco

This example doesn't work any more.  You compile error now with 'Expression cannot be assigned'

 

Any have the current correct answer to this question.

bob_buzzardbob_buzzard

This should still work, as its just assigning a value to a field.

 

Which line gives the error - the instantiation or the assignment of the field?