0

I got a problem with @wire. To get refreshed data I need to refresh the whole page manually. If I switch to another navigation item add or delete records, nothing happens after returning to the navigation item where my component is placed

My Code (I removed components from the code, retrieved objects could be seen in consloe.log())

 <template>

    <lightning-card title="Tasks" variant="Narrow" icon-name="standard:task">
        

   </lightning-card>

</template>




import {LightningElement, track, wire} from 'lwc';
import getToDoList from '@salesforce/apex/ToDoController.getToDoList'
import {ShowToastEvent} from 'lightning/platformShowToastEvent';

export default class ToDosContainer extends LightningElement {


    @track records;

    @wire(getToDoList) wiredRecords({error, data}){
        if (data){
            console.log(data);
            this.records = data;
        } else if (error){
            console.log(error);
        }
    }


}
1
0

Automatic refresh of data as a side-effect of a record change will happen if your wire uses the standard uiRecordApi services, since a lightning record page uses these services too. My experience is that wires against those services will be triggered when the cache for that data is updated.

If you cannot use these standard services, an alternative is for you to leverage Lightning EMP and an appropriate streaming channel that notifies your component(s) about changes that they should be aware of. In this scenario you will likely still need to use the refreshApex API in your component, when you receive the streaming notification, to ensure that the client-side cache of your wire's response doesn't prevent update of the underlying data from the server.

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.