5

I notice one problem with @wire(getRecord, { recordId: "$recordId", fields: FIELDS }). It normally works good, automatically changes when a field changes in the page but, if we have a roll-up summary field on the object that counts records, and we put that field in the fields var that goes into the @wire method. If you delete a record in a standard related list, the @wire does not changes automatically.

And the deletion also does not a refreshView, and in aura component to handle this type of situation I listen to the toast event with type=success to handle the logic.

I don't like this type of handling because it has a lot of toasts in the process and is very inefficient.

Someone knows a better way for this type os situations?

Thank you in advance

4

Today changes to cross-record summary fields, like rollups, are not detected by Lightning Data Service. We're actively working on a feature whereby Lightning Data Service (and all of its @wire adapters) will automatically provision a new version of records when such fields change regardless of the technology that triggered the change: LWC, Aura, Visualforce, Apex, triggers, etc. This means your components are reactive to record data changes regardless of the source. This also eliminates your need as a developer to know when to refresh which records. There's an open pilot for this; contact your account / support manager to join the Live Records pilot.

If Lightning Data Service detects a record is deleted then @wire(getRecord) uses will provision an error object with status code 404 (resource not found). Detection works if it's done using deleteRecord() in LWC or force:recordData's deleteRecord() method in Aura.

  • When I know that there is update to the record in database, I can invoke refreshApex for manually refreshing cached Apex method response, but how to manually refresh cache for getRecord (or any other wired service) ? – salesforce-sas Sep 26 at 8:25
  • I asked same question HERE – salesforce-sas Sep 26 at 8:34
1

I believe the issue is that you're using the wire service which requires your aura enabled method to cache results. You should be able to use refreshApex to get the desired effect. Something like the below should do the trick.

import { LightningElement, track, wire, api{ from 'lwc';
import { refreshApex } from '@salesforce/apex';
import fetchAccount from '@salesforce/apex/testComponentController.fetchAccount';
export default class TestComponent extends LightningElements {
    @track accountId;
    @track acc;
    @wire(fetchAccount,{param1:'$accountId'})
    someFunction(result){
        if(result.data) this.account = result.data;
    }

    someOtherFunction(){
        refreshApex(this.acc);
    }
}
  • Thank you for your answer. I'm not utilizing apex, I'm utilizing Lightning Data Service to fetch data from one record. If you have some question, I can try to be more clear with my question. Thank you again. – Elias Pinheiro Apr 28 at 8:40
  • 1
    @EliasPinheiro refreshApex should work regardless of the wire type. It should have been named refreshWire or something more generic – James Loghry May 1 at 2:30
  • hello @JamesLoghry, but how I do the refreshApex, because I need the event when a user deletes a record in the standard related list. Now I do with listening the toast event, but I don't like this approach. – Elias Pinheiro May 7 at 8:24

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.