+ Start a Discussion
Josh Davis 13Josh Davis 13 

List button to update multi select picklist field

I'd like to have a list button to update a multi-select picklist field. The javascript below runs when I click it on a related contact list on an account page (I get the alert with the Id), but the checked record does not update. I suspect it's due to the multi-select field type, because this code worked for regular picklist in this answer.
I have enabled Account Contact Relationships, and want to update the Roles field in that object with a text value ("Former resident"). Here's the code:

    var selectedRecords = {!GETRECORDIDS( $ObjectType.AccountContactRelation )};
    if(selectedRecords.length > 0){
        var recordsToUpdate = [];
        for(var i = 0; i < selectedRecords.length; i++){
            var record = new sforce.SObject("AccountContactRelation"); 
            record.Id = selectedRecords[i];
            record.Roles = 'Former resident;'; /* also tried without inner semicolon */
alert('Updated ' + selectedRecords[i] );  /* this works */

        var result = sforce.connection.update(recordsToUpdate);  /* this doesn't work */

        alert('Please select at least one row');
sukanya banekarsukanya banekar
Make below modification to your code.
​var result = sforce.connection.update([recordsToUpdate]);

Let me know if this works.

Sukanya Banekar

Josh Davis 13Josh Davis 13
Thank you Sukanya. It did not change the result.