+ Start a Discussion

New record is created instead of update in LWC?

I have to update Case record. So, I have created custom button, which call lightning component, which in turn calls lightning web component. LWC will display the screen perfectly. But when I enter the data and click save. New record is getting created instead of update. How to resolve this issue please ? I followed this link .. https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_update_record . it did not work .. I have doubt.. the apex class ..it's quering one record from case.. we are not even passing any id .. how would it get the right case ????so, I modified the code ..still an issue.  Here is the code 


 record-id={recordId} record-type-id={recordTypeId} onsuccess={handleSuccess}> -->
    <lightning-record-edit-form record-id={recordId} object-api-name="Case" columns="1"  mode="edit" density="auto" layout-type="Compact"  onsuccess={handleSuccess} onsubmit ={handleSubmit}>    
        <div class="slds-m-around_medium">
            <div class="slds-section">
                <h3 class="slds-text-heading_large slds-text-align_center">               
                    Testing Case Update          
            <br />
            <div class="slds-grid slds-gutters">
                <div class="slds-col slds-size_1-of-2 csclass">
                    <lightning-input-field field-name='Test_Date__c'></lightning-input-field>
        <lightning-button variant="brand-outline" type="submit" name="save" label="Update Case" onclick={showHandler} class="slds-align_absolute-center"></lightning-button>

Java Script

import { LightningElement, api } from 'lwc';

export default class Test_Case extends LightningElement {
    @api recordId;
    handleSubmit(event) {
     console.log('onsubmit: '+ event.detail.fields);
    handleSuccess(event) {
        const updatedRecord = event.detail.id;
        console.log('onsuccess: ', updatedRecord);
XML File    
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
        <targetConfig targets="lightningCommunity__Default">
                label="Record Id"
                description="Automatically bind the page's record id to the component variable"
                default="{!recordId}" />