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
shaanRocksshaanRocks 

Passing values to multipicklist Field

 

How can i pass values form a string to multipicklist field.

I need to update a multipicklist field.

 

I have concatenated a list of values to a string as:

 

string str = '1; 2; 3; 4';

 

I thought of passing these values directly to the field but the field is not being updated.

Please let me know what needs to be done.

 

Best Answer chosen by Admin (Salesforce Developers) 
shaanRocksshaanRocks

Please paste the code you have written.

I have tried using replaceAll method but it is not working.

 

 Here is my Requirement:

 

I have  a Value stored in string now how to pass value of a string to a multi picklist field of an object using apex code.

 

I have a value stored in a string as:

string str =

004 - Florida;008 - Ohio River;013 - Carolinas;015 - Texas;024 - Gulf Coast;024 - Gulf Coast;030 - Empire State;040 - Sun Coast;032 - Pacific Northw;029 - Rocky Mountain

All Answers

IvarIvar

Hi there.

 

I am pretty sure, based on code I have written, that you should be able to do that exactly. Have you checked if other parts of your code are in error?

 

Regards,

Ivar

 

 

shaanRocksshaanRocks

Please paste the code you have written.

I have tried using replaceAll method but it is not working.

 

 Here is my Requirement:

 

I have  a Value stored in string now how to pass value of a string to a multi picklist field of an object using apex code.

 

I have a value stored in a string as:

string str =

004 - Florida;008 - Ohio River;013 - Carolinas;015 - Texas;024 - Gulf Coast;024 - Gulf Coast;030 - Empire State;040 - Sun Coast;032 - Pacific Northw;029 - Rocky Mountain
This was selected as the best answer
IvarguIvargu

Hi again shaanRocks.

 

I can't unfortunately paste the code since it was for a client and not my property, but I whipped up an extremely simple piece of code that works to illustrate the assignment.

 

I logged into my development org, created a new object called "Nugget", and on that I created a new Multiselect picklist named "mplMultilist__c'.

 

I then created this very simple trigger that works and illustrates how you assign the string value to the field:

trigger updateMuliPicklist on Nugget__c (before insert, before update) {
    for( Nugget__c n: Trigger.New ){
        n.mplMultilist__c = 'Value One; Value Two; Value Three';
    }
}

 If I now create a new Nugget object the multilist is set to those three values.

 

Hope this helps clarify.

 

Regards,

Ivar

 

 

shaanRocksshaanRocks

Hi Ivar,

Thanks for your reply. The issue was with my code.

Now its working fine can pass directly a string to multipicklist.

 

Thanks again!