+ Start a Discussion
KeithlarsKeithlars 

Appending values to multi select picklist

I'm new to Apex so this is going to be my first crack at it.
I have two multi select picklist, one with current values and one with historical values.  I need to add any values from the current picklist to the historical picklist that aren't already there. 
I assume I need to write a trigger that will do this.  I can find examples on updating fields, but none dealing with multi select picklist.  Any sample code you can share would be greatly appreciated.
 
Keith
Vijay RautVijay Raut
In MultiSelect picklist, values are separated by semicolon (;). So when you are trying to set multiselect picklist value use following syntax in trigger.

OBJECT.MULTI_SELECT_FIELD__c = OLD_VALUE + ';' + NEW_VALUE;

Hope this would help.

Cheers,
V.R.

KeithlarsKeithlars

Thanks.  Does it matter if the old value is already there and I add it again?

 

Keith

Vijay RautVijay Raut
Hi,

Yeah. It does matter. It would show multiple time on detail page layout. To avoid this, check if value is already present and push if it is not there.

Cheers,
V.R.