2

I have created an LWC to edit a custom object record. The LWC is wrapped around Aura component that is used to override standard edit button. Once I create a record of the custom object and open for edit, the LWC opens and works fine. Now if I go back to the custom object tab (i.e. to a list view) and delete the record that was previously opened in the LWC, the LWC tries to access the deleted record and I get error. The LWC gets recordId as API input of the record to open for edit. I tried two options,

  1. In LWC, I have a wired call to retrieve the record using getRecord(recordId:$recordId). Once I open a record with the LWC, go back to the custom object tab and delete the record that was opened, this wired method gets called even if the LWC is not open/visible. It seems to be sitting in DOM. Because of this, I get error since the record is deleted.

  2. In LWC, in connectedcallback, I use my own apex method to retrieve the record details and initialize it to open. Then go back to the custom object tab to delete the record. At this point it seem to be calling something that gives me "Error. NOT_FOUND". Not sure what's calling it. I do not see anything in my code that show this error.

I am wondering why it calls my LWC method when a record (that was previously opened in my LWC) is deleted? The LWC instance seems to be in the DOM. Since I have LWC displayed in an app page, I can simply click the custom object tab so looks like the LWC instance still stays in DOM. Not sure if there is a way to remove the LWC instance from DOM when user goes away from the LWC instance by clicking another tab.

1 Answer 1

1

Some features of lightning/ui is still in beta, maybe the @wiredecorator is firing even though you're on list liew.

Can you try using this instead for getting the recordId, assuming your component will be in the record page;

    import { LightningElement, api } from 'lwc';
    export default class TestClass extends LightningElement {
        @api recordId;
    }
1
  • 1
    My component gets the recordId as API public property. Utilizing this recordId, it uses Salesforce/ui getRecord() in a wired method to retrieve the record details. The same wired method gets called when a record that was opened in my LWC gets deleted from a tab list view. When I delete the record, my LWC is not visible however somehow SF calls the wired method in my LWC since it's in the DOM and it was using the recordId. Oct 30, 2019 at 16:47

You must log in to answer this question.

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