0

I have worked on LWC requirement where

  1. On Case record, I have customized a component, which is based on custom metadata for the UI display and multi picklist for the back end.
  2. As a case owner ONLY I CAN EDIT or selected a picklist, it will display the options based on picklist from the custom metadata(the same value will be in the multi picklist in the backend). 3)The issues I am having are how can I after saving the record a) refresh the page to display the checked boxes and b) disable the picklist chosen but not the options.
import { LightningElement, track,api } from 'lwc';
import checkOwnerId from '@salesforce/apex/checkCaseFieldsCaseOwner.checkCurrentUserIsRecordOwner';
import getCustumMetadata from '@salesforce/apex/checkCaseFieldsCaseOwner.getCustumMetadata';
import updateCasewithChosenvalues from'@salesforce/apex/checkCaseFieldsCaseOwner.updateCasewithChosenvalues';
export default class TodoMultipicklistCustom extends LightningElement {
    @track options=[];
    @api recordId;
    @track checkboxesString;
    
    connectedCallback(){
        checkOwnerId({recordId: this.recordId})
            .then(result => {
                if(result){
                    this.disabled = false;
                }
            })
            .catch(error => {
                this.error = error;
            });
    }

    get brokerOptions() {
        return [
            { label: 'None', value: 'None'},
            { label: 'State Farm Principal Officer', value: 'State Farm Principal Officer' },
            { label: 'State Farm Licensed Team Member', value: 'State Farm Licensed Team Member' }
        ];
    }

    handleChange(event) {
        this.value = event.detail.value;
        this.options.length=0;
            getCustumMetadata({Type :  this.value })
                .then(result => {
                    console.log(JSON.stringify(result));
                    let  optionsObject;
                    //result.forEach(element => console.log(element));
                    result.forEach(element=>{
                        optionsObject = new Object();
                        optionsObject.label = element;
                        optionsObject.value = element;
                        console.log('+++++options*'+ JSON.stringify(optionsObject))
                        this.options.push(optionsObject);
                        console.log('***'+ JSON.stringify(this.options))
                    });
                    console.log(JSON.stringify(this.options));
                })
                .catch(error => {
                    this.error = error;
                });
    }
    handleCheckboxgroup(event) {
        let data;
        data = event.target.value;
        this.checkboxesString=data.split(',').join(':');
        console.log('*****'+ this.checkboxesString);
    }
    updateCase(){
        updateCasewithChosenvalues({
            recordId: this.recordId,
            ToDo_Typ: this.value,
            optionsChecked: this.checkboxesString
        })
        .then(()=>{
        })
        .catch((error)=>{
            this.errorMessage=error;
            console.log('unable to save the record due to'+JSON.stringify(this.errorMessage));
        });
    }
}

3 Answers 3

0

Use the Lightning Data Service's updateRecord method to update your Case record instead of using an imperative apex method. The record data refreshes automatically as LDS refreshes the view if the cache is stale.

PS: You could also get the current record details using LDS' getRecord method instead of an Apex call in the case of checking OwnerId.

0

So i used .then(result => { this.Case = result;

    window.location.assign('/'+ this.recordId);
})

to refresh the page, but I am not able to display the previously saved the multiselect values? Any suggestions why

0

One can use this getRecordNotifyChange(recordId) to refresh the standard salesforce component to refresh (without actually refresh the browser) after saving a field from a custom component provided the custom component in the record page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .