function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JohnDuraiJohnDurai 

Need help on refreshing Page on Lightning web component

I have Notes component placed on record page which will refer field, the coponent is getting refreshed in UI when we update something inside component but when i refresh the whole page then only it is getting updated on record page, I need to referesh record page as well on updating the component. I am aware that ther is somethingn called "Apedrefresh" can someone help me on this, 

This is my wire method:

* -----------------------------------------
        WIRE METHODS 
       ----------------------------------------- */
    @wire(getFieldInfo, { recordId: '$recordId', fieldName: '$fieldName' })
    wiredFieldInfo({error, data}){
        if(error){
            this.processError(error);
        } else if(data){
            var fieldData = JSON.parse(JSON.stringify(data));
            if(data.fieldDescribe){
                fieldData.fieldDescribe = JSON.parse(data.fieldDescribe);
                if(!this.modalTitle){
                    this.modalTitle = fieldData.fieldDescribe.label;
                }
                  this.accessible = data.fieldAccess;
                  this.updateable= fieldData.fieldDescribe.updateable;
                  this.disabled = !(this.updateable);
                  this.fieldlength = fieldData.fieldDescribe.length;
            }
            if(data.fieldValue){
                this.fieldValue = data.fieldValue;
                this.iconName = FILLED_NOTE_ICON;
            }
        }
    };

this is my save notes handler:

 saveNotes(){
        var context = this;
        this.isLoading = true;
        saveNotesInfo({recordId: this.recordId, fieldName: this.fieldName, fieldValue: this.fieldValue})
            .then((result) => {
                context.showSuccessToast('Success', context.modalTitle + ' successfully saved');
            })
            .catch((error) => {
                context.processError(error);
            })
            .finally(() => {
                context.isNotesModalOpen = false;
                this.isLoading = false;
                if (this.fieldValue === '') {
                    this.iconName = EMPTY_NOTE_ICON;
                    
                } else {
                    this.iconName=FILLED_NOTE_ICON;
                    
                }
            });
    }
Best Answer chosen by JohnDurai
CharuDuttCharuDutt
Hii 
Try The Following Code 
I've Made Some Changes
import { refreshApex } from '@salesforce/apex';

wiredActivities;/*Property Name*/
 
@wire(getFieldInfo, { recordId: '$recordId', fieldName: '$fieldName' })
     wiredclass(value){
      this.wiredActivities = value;
      const { data, error } = value;
        if(error){
            this.processError(error);
        } else if(data){
            var fieldData = JSON.parse(JSON.stringify(data));
            if(data.fieldDescribe){
                fieldData.fieldDescribe = JSON.parse(data.fieldDescribe);
                if(!this.modalTitle){
                    this.modalTitle = fieldData.fieldDescribe.label;
                }
                  this.accessible = data.fieldAccess;
                  this.updateable= fieldData.fieldDescribe.updateable;
                  this.disabled = !(this.updateable);
                  this.fieldlength = fieldData.fieldDescribe.length;
            }
            if(data.fieldValue){
                this.fieldValue = data.fieldValue;
                this.iconName = FILLED_NOTE_ICON;
            }
        }
    }


saveNotes(){
        var context = this;
        this.isLoading = true;
        saveNotesInfo({recordId: this.recordId, fieldName: this.fieldName, fieldValue: this.fieldValue})
            .then((result) => {
                context.showSuccessToast('Success', context.modalTitle + ' successfully saved');
                return refreshApex(this.wiredActivities);
            })
            .catch((error) => {
                context.processError(error);
            })
            .finally(() => {
                context.isNotesModalOpen = false;
                this.isLoading = false;
                if (this.fieldValue === '') {
                    this.iconName = EMPTY_NOTE_ICON;
                    
                } else {
                    this.iconName=FILLED_NOTE_ICON;
                    
                }
            });
    }
Please Mark it As Best if it Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii 
Try The Following Code 
I've Made Some Changes
import { refreshApex } from '@salesforce/apex';

wiredActivities;/*Property Name*/
 
@wire(getFieldInfo, { recordId: '$recordId', fieldName: '$fieldName' })
     wiredclass(value){
      this.wiredActivities = value;
      const { data, error } = value;
        if(error){
            this.processError(error);
        } else if(data){
            var fieldData = JSON.parse(JSON.stringify(data));
            if(data.fieldDescribe){
                fieldData.fieldDescribe = JSON.parse(data.fieldDescribe);
                if(!this.modalTitle){
                    this.modalTitle = fieldData.fieldDescribe.label;
                }
                  this.accessible = data.fieldAccess;
                  this.updateable= fieldData.fieldDescribe.updateable;
                  this.disabled = !(this.updateable);
                  this.fieldlength = fieldData.fieldDescribe.length;
            }
            if(data.fieldValue){
                this.fieldValue = data.fieldValue;
                this.iconName = FILLED_NOTE_ICON;
            }
        }
    }


saveNotes(){
        var context = this;
        this.isLoading = true;
        saveNotesInfo({recordId: this.recordId, fieldName: this.fieldName, fieldValue: this.fieldValue})
            .then((result) => {
                context.showSuccessToast('Success', context.modalTitle + ' successfully saved');
                return refreshApex(this.wiredActivities);
            })
            .catch((error) => {
                context.processError(error);
            })
            .finally(() => {
                context.isNotesModalOpen = false;
                this.isLoading = false;
                if (this.fieldValue === '') {
                    this.iconName = EMPTY_NOTE_ICON;
                    
                } else {
                    this.iconName=FILLED_NOTE_ICON;
                    
                }
            });
    }
Please Mark it As Best if it Helps
Thank You!
This was selected as the best answer
JohnDuraiJohnDurai
Hi @CharuDutt - component is getting referessed but tts not refreshing the record page automatically, 
CharuDuttCharuDutt
Record Page refresh only When you Make Changes In Record Upon Clicking Save Button or Manually refreshing Page
 
JohnDuraiJohnDurai
@charuDutt - I am placing the component in record page and referring a field from record page in that component, when i update something in the component then it should update the field in record page as well without refeshing the whole record page. right now the behaviour is only component getting reffreshed but not the field on record page, just looking for the way to refresh the record page so that field will also get updated when we do changes in component