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',
                    }),
                );
        });
  • 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. – Anshul Agrawal Jul 1 '19 at 17:05
  • Made it work by explicitly handling the force:refreshView event. – Anshul Agrawal Jul 1 '19 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 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(); } – Anshul Agrawal Feb 5 at 18:22

Your Answer

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

Browse other questions tagged or ask your own question.