sSample HTML Code:

<lightning-record-edit-form object-api-name="Opportunity" onsubmit={firesubmit} > 
 <div class="slds-grid">
 <div class="slds-col slds-size_1-of-2">
<lightning-input-field field-name="field1"></lightning-input-field> 
<lightning-input-field field-name="field2"></lightning-input-field>
<lightning-input-field field-name="field3"></lightning-input-field> 
<lightning-button type="submit" variant="brand" label="Save" onclick={saveClick}></lightning-button>

Sample JavaScript Code below

firesubmit(event) {
    this.fields = event.detail.fields;

saveClick (event) {
    const myfield = event.detail.fields;
    myfield.field4 = "Hello";

On click of Save button, i'm getting undefined error. Can you suggest as how to pre-default value in field before submitting a record through Custom button?

Note: I followed an approach mentioned in this link Save & New Button in LWC

2 Answers 2


I found a good example here ... https://medium.com/@strusov/lwc-lightning-record-edit-form-set-or-modify-field-values-onsubmit-9f00199bc2a

In this particular case you can do the following:

/* form */
<div class="slds-form__item slds-hide" role="listitem">
    <lightning-input-field field-name="Color__c">
/* end form*/

/* JS. onSubmit */
const fields = event.detail.fields;
fields.Color__c = this.selectedColor;
/* END JS. onSubmit */

Basically include the field in the form and hide it.

  • 2
    Welcome to SFSE! While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Commented Oct 8, 2020 at 18:29

in your code you have

 const myfield = events.detail.fields;

instead of

   const myfield = event.detail.fields;
  • That was typo mistake. I'm still not able to pre-default values.
    – Arjun SFDC
    Commented May 18, 2020 at 16:56

You must log in to answer this question.

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