Salesforce apex how to save checkbox multiple values in database

121 views Asked by At

I am trying to save the values from checkbox group in apex. I have converted the values from comma delemited to a list of strings. How can I save the values into the picklist type field. I have checkbox group of colors and there is a picklist field in the custom object which saves color options you choose at the front end.

in Lightning page

get acc_status_options() {
        return [
            { label: 'Black', value: 'Black' },
            { label: 'White', value: 'White' },
            { label: 'Red', value: 'Red' },
            { label: 'Yellow', value: 'Yellow' },
            { label: 'Green', value: 'Green' },
        ];
    }

in apex i am receiving the parameter as comma delimited string and converting it to the list of String.

List selectedColors = colors.split(',');

How to save this multiple selected list values into the database field

MyObj obj = new MyObj(); obj.yourcolors__c = selectedColors;

insert obj;

I am getting error. Can not save record.

1

There are 1 answers

2
eyescream On BEST ANSWER

Multipicklists store the values separated by semicolons, not commas. So either a replaceall or string.join(colors, ';'); should do the trick.