1

I am trying to refresh my community page which has a LWC with a submit button. The page has a relatedlist also which is a junction object where the mapping from LWC is getting stored. What, i want when i save my records the page should auto refresh and the related list should show the updated mapping. I tried navigating to my current page but the related list isnt updating until i do a hard refresh! I have tried even putting a delay! In console i can see my records are created before the page is navigated. How can i resolve this ?

createRecord(recordInput)
            .then(() => {
            for (let i = 0; i < this.selectedRows.length; i++){
                //alert("You selected: " + this.selectedRows[i].locationId);
                const fields = {};
                fields[CLIENT_FIELD.fieldApiName] = this.recordId;
                fields[LOCATION_FIELD.fieldApiName] = this.selectedRows[i].locationId;
                fields[STARTDATE_FIELD.fieldApiName] = this.startDate;
                const recordInput = { apiName: CLIENT_LOCATION_OBJECT.objectApiName, fields };
                createRecord(recordInput)
                    .then((clientLocation) => {
                    console.log('client location created >'+clientLocation.id);
                    counter++;

                });
            }
        }).then(() => {
                /*this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Locations are mapped.',
                        variant: 'success'
                    }),
                );*/
            setTimeout(() => {
                this[NavigationMixin.Navigate]({
                    type: "standard__recordPage",
                    attributes: {
                        objectApiName: "Account",
                        actionName: "view",
                        recordId: this.recordId,
                    },
                });
            }, DELAY);
        }).catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: this.label.labelError,
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
        });
4
  • I tried - $A.get('e.force:refreshView').fire(); by wrapping my LWC in Aura, i am able to call refresh through events but the page doesnt do anything. Jul 1, 2019 at 17:05
  • Made it work by explicitly handling the force:refreshView event. Jul 1, 2019 at 23:23
  • can you explain/elaborate on what you mean by "force:refreshView"? How did you solve for the issue?
    – Paul N
    Feb 5, 2020 at 15:55
  • @PaulN , When i fired the above mentioned event, i wrote a handler for it also <aura:handler event="force:refreshView" action="{!c.isRefreshed}" /> which just refreshed the lightning page. isRefreshed: function(component, event, helper) { location.reload(); } Feb 5, 2020 at 18:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.