2

I'm referring to the document to make use of out of box import { updateRecord, } from 'lightning/uiRecordApi'; It is straight forward to understand how to pass field values from the given example in the document for updateRecord. updateRecord

 const fields = {};
        fields[ID_FIELD.fieldApiName] = this.contactId;
        fields[FIRSTNAME_FIELD.fieldApiName] = this.template.querySelector("[data-field='FirstName']").value;
        fields[LASTNAME_FIELD.fieldApiName] = this.template.querySelector("[data-field='LastName']").value;

        const recordInput = { fields };

        updateRecord(recordInput)
            .then(() => {

Example is for single values. My question is if one of the field is a multi select picklist, say states, how do I pass that value ( even hard coded ) to the field name in LWC js. I tried many combinations

  1. fname__c:"NY;CT;NJ"
  2. fname__c:["NY","CT","NJ"]

nothing seems to work

0

According to Documentation, The updateRecord uses ui-api and accept the recordInput as parameter.

One of the properties of recordInput is fields. If you have a multiselect picklist, you can pass the value like this:-

MultiPicklist—JSON String (for example, Dog;Cat;Fish).

I have tried it in workbench and it worked:-

enter image description here

Coming to LWC, You can pass multiselect value as:-

fields[MULTISELECT_FIELD.fieldApiName] = "value1;Value2;value3";

Also, do not forget to import the multiselect field first as follow:-

import MULTISELECT_FIELD from '@salesforce/schema/ObjectApiName.FieldApiName';
  • Thank you. This is the mistake I did. Even though the document says fields[FIRSTNAME_FIELD.fieldApiName] ="myvalueforthisfield"; it will also work if we write this line like this fields['FirstName'].value = "myvalueforthisfield"; that is without actually importing the field . But that approach will fail for multi value fields. So as you said IMPORT FIELD and bind it the documented way fields[MULTISELECT_FIELD.fieldApiName] and pass the values as semicolon separated string. – vinod Oct 13 '20 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.