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
Debabrata BeraDebabrata Bera 

$A.get('e.force:refreshView').fire(); - giving undefined error in lightning.

$A.get('e.force:refreshView').fire();
I am getting error - 'Cannot read property 'fire' of undefined'. This is weired. Plz help me if you have any suitable answer.
Best Answer chosen by Debabrata Bera
Khan AnasKhan Anas (Salesforce Developers) 
Hi Debabrata,

Greetings to you!

The default refreshView event is only available within the Lightning Experience and Salesforce mobile app. If you want to use the event within a custom lightning app ( .app) you have to handle the event manually and cannot use the out-of-the-box behavior.

So, in your component, you need to handle the event.
 
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

And in the controller, you can fire the event.
 
save : function(component,event,helper){
        
        var action = component.get("c.apexSave"); 
        action.setCallback(this, function(action) {                
           $A.get('e.force:refreshView').fire(); 
        }); 
        $A.enqueueAction(action); 
    },

    /*page refresh after data save*/    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },

For more information refer below link.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_one.htm

Also, Lightning statndard events like $A.get("e.force:refreshView").fire(); are not supported when lightning component is used in visualforce pages.

If the problem still persists, I suggest you please share your complete code.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Debabrata,

Greetings to you!

The default refreshView event is only available within the Lightning Experience and Salesforce mobile app. If you want to use the event within a custom lightning app ( .app) you have to handle the event manually and cannot use the out-of-the-box behavior.

So, in your component, you need to handle the event.
 
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

And in the controller, you can fire the event.
 
save : function(component,event,helper){
        
        var action = component.get("c.apexSave"); 
        action.setCallback(this, function(action) {                
           $A.get('e.force:refreshView').fire(); 
        }); 
        $A.enqueueAction(action); 
    },

    /*page refresh after data save*/    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },

For more information refer below link.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_one.htm

Also, Lightning statndard events like $A.get("e.force:refreshView").fire(); are not supported when lightning component is used in visualforce pages.

If the problem still persists, I suggest you please share your complete code.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Debabrata BeraDebabrata Bera
Thanks for your help and working fine now. I completly missed that part.
Aman Chawla 2Aman Chawla 2
I added 
location.reload();


to reload my entire page. Works like a charm. Love the native javascript :) 
Ankit Bhati 1Ankit Bhati 1
Thanks @Khan Anas for sharing post. I also get stuck while reload page