You need to sign in to do that
Don't have an account?
anantha Lakshmi kuppala
existing record not updating, it is inserting new record. I would like to update new record. Any suggestions please?
import { api, LightningElement } from 'lwc';
import contactFirstName from '@salesforce/schema/Contact.FirstName';
import contactLastName from '@salesforce/schema/Contact.LastName';
import contactEmail from '@salesforce/schema/Contact.Email';
import contactPhone from '@salesforce/schema/Contact.Phone';
import contactAccount from '@salesforce/schema/Contact.AccountId';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class updateRecordLwc extends LightningElement {
@api ContactObjectApiName='Contact';
@api recordId;
ContactFieldList = [contactFirstName,contactLastName,contactEmail,contactPhone,contactAccount];
contactHandleUpdate(event){
const evt = new ShowToastEvent({
title:'Record Updated',
message:'Contact record: ' + event.detail.fields.LastName.value + 'is successfully updated',
variant:'success',
})
this.dispatchEvent(evt);
}
}
Html
<template>
<lightning-card title="LWC Example 2">
<br/><br/>
<h2 class="slds-text-color--error">How to Edit/Update record without apex class by help of the lightning data service in LWC</h2>
<lightning-record-form object-api-name={ContactObjectApiName} fields={ContactFieldList} record-id={recordId} onsuccess={contactHandleUpdate}></lightning-record-form>
<br/><br/>
</lightning-card>
</template>
import contactFirstName from '@salesforce/schema/Contact.FirstName';
import contactLastName from '@salesforce/schema/Contact.LastName';
import contactEmail from '@salesforce/schema/Contact.Email';
import contactPhone from '@salesforce/schema/Contact.Phone';
import contactAccount from '@salesforce/schema/Contact.AccountId';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class updateRecordLwc extends LightningElement {
@api ContactObjectApiName='Contact';
@api recordId;
ContactFieldList = [contactFirstName,contactLastName,contactEmail,contactPhone,contactAccount];
contactHandleUpdate(event){
const evt = new ShowToastEvent({
title:'Record Updated',
message:'Contact record: ' + event.detail.fields.LastName.value + 'is successfully updated',
variant:'success',
})
this.dispatchEvent(evt);
}
}
Html
<template>
<lightning-card title="LWC Example 2">
<br/><br/>
<h2 class="slds-text-color--error">How to Edit/Update record without apex class by help of the lightning data service in LWC</h2>
<lightning-record-form object-api-name={ContactObjectApiName} fields={ContactFieldList} record-id={recordId} onsuccess={contactHandleUpdate}></lightning-record-form>
<br/><br/>
</lightning-card>
</template>
Please follow below code , you need to use lightning-record-edit-form
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Refer the below link have similar kind of solution.
https://www.swdcworld.com/2020/08/update-any-record-without-using-apex.html
Thanks!!