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
fiona gentryfiona gentry 

How To Write LWC code Logic to Save a Record After Value selected using lightning-combobox

Hi Gurus,
For some requirment ,i cannot use lightning-record-edit-form ,hence i am using lightning-combobox to get the field values from Apex controller and displaying in LWC component..Controller Looks like this
 
public with sharing class ERT_MultiLevelSelectEdit {
  
    @AuraEnabled(cacheable=true)
public static list<ERT_Case_Type__c> getExistingERTLevels(String ERTId)
{
  
  return [Select Id, Level_1__c,Level_2__c,Level_3__c from ERT_Case_Type__c WHERE Id =:ERTId];
}
    
}

App html is 
<template>
    <lightning-card title="ERT Case Edit- Lightning Web Component" icon-name="custom:custom63">
        <lightning-combobox
            name="Level_1__c"
            label="Level 1"
            placeholder="Choose Level 1 To Edit"
            value={value}
            onchange={handleChange}
            options={statusOptions}>
        </lightning-combobox>
        
    </lightning-card>
</template>

And app JS is below
import { LightningElement, api, wire, track } from 'lwc';

import getExistingERTLevels from '@salesforce/apex/ERT_MultiLevelSelectEdit.getExistingERTLevels';
let i=0;

export default class ERT_MultiLevelSelectEditLWC extends LightningElement {
     /** Id of record to display. */
    @api recordId; //this captures ERTId which is passed from Parent Component
    @track error;   //this holds errors

    @track items = []; //this holds the array for records with value & label

    @track value = '';  //this displays selected value of combo box

    /* Load ERT records based on ERT Record Id from Controller */
    @wire(getExistingERTLevels, { ERTId: '$recordId'})
    wiredERTLevels({ error, data }) {
        if (data) {
            for(i=0; i<data.length; i++) {
                console.log('id=' + data[i].Id);
                this.items = [...this.items ,{value: data[i].Id , label: data[i].Level_1__c,label: data[i].Level_2__c,label: data[i].Level_3__c}];                                   
            }                
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.contacts = undefined;
        }
    }
   
    //getter property from statusOptions which return the items array
    get statusOptions() {
        console.log(this.items);
        return this.items;
    }

    handleChange(event) {
        // Get the string of the "value" attribute on the selected option
        const selectedOption = event.detail.value;
        console.log('selectedOption=' + selectedOption);

        //This is for event propagation
        
        const filterChangeEvent = new CustomEvent('filterchange', {
            detail: { selectedOption },
        });

        
        // Fire the custom event
        this.dispatchEvent(filterChangeEvent);
    }
    
}

Please help me how do i write a logic to save the record successfully Back to Controller

Regards,
Fiona