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
Abdulhannan Patel 8Abdulhannan Patel 8 

Space in the multi select picklist value via apex!

Can we have space in the Multi select picklist value? On UI, it works and creates the record with this field however, using apex, if I pass space in the multiselect picklist field, it shows bad value error. Is there any limitation of multi picklist field? Please help.
Best Answer chosen by Abdulhannan Patel 8
Sampath SuranjiSampath Suranji
Is that so. May be any other issue there. I suggest you to delete the pick list and recreate and try again.
User-added image
User-added image

regards

All Answers

Abdulhannan Patel 8Abdulhannan Patel 8
I have customers__c multiselect field on account. Below code throws Bad Value error -

Account a = new Account();
a.Name = 'Test Account';
a.customers__c ='US Customers'
insert a;

On UI it takes this value and works fine. However, the apex gives an error.
Sampath SuranjiSampath Suranji
Hi,
We can have a space in the pick list value. Please double check exact value is same as 'US Customers' inside the Multi select pick list values.
Most probably it may differ.

regards
Abdulhannan Patel 8Abdulhannan Patel 8
Hi Sampath, Thank you for your response. I checked it again. The value is exactly same in the picklist values. On UI, this value is accepted but not via apex. Regards, Abdul
Sampath SuranjiSampath Suranji
Is that so. May be any other issue there. I suggest you to delete the pick list and recreate and try again.
User-added image
User-added image

regards
This was selected as the best answer
Abdulhannan Patel 8Abdulhannan Patel 8
Thank you Sampath. Deleting and creating a new picklist field worked 😉 Not sure why it was showing the error before. Though, it has got same values.