0

I use the lightning-record-edit-form for my custom lead conversion and override the save button. However I cannot find a good documentation to get the updated values of the lead. The lead needs to be updated before conversion. I'am calling an apex method to convert the lead. TIA.

1

I don't believe the lightning-record-edit-form component has any ways built-in to do this. On a submit event its fields property contains all of the fields available on the form, so that will include both changed and unchanged values:

handleOnSubmit(event) {
    event.preventDefault();

    // Get the fields from the submit event
    let fields = event.detail.fields;
    
    // check, compare, modify field values
    console.log(fields.Country);
    fields.Name = fields.Name + fields.Phone;

    // custom logic in here before submission

    // pass the fields on
    this.template.querySelector('lightning-record-edit-form').submit(fields);
}

If you want to identify the changes you have three options as far as I can see.

  1. Let the submit request hit the server and use an Apex method to compare the new values with the old and only commit the updated values. This ensures the comparison happens on the server, but it would require querying for the current state of the Lead in the Apex class and unless you have a good need for doing a field by field comparison, the DML operation will handle updating only the changed values for you anyways.
  2. Keep a copy of the original state of the Lead in your LWC. So when you fetch the Lead, make a clone of it that you can compare the changes to.
  3. Keep track of the fields that were accessed and modified in the component. This is my least favored option as it would likely involve the most code and maintenance going forward and could slow your component down as you check for each change.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.