3

I have created a lightning component for the lightning experience record pages. In the customize record page, I drag standard Record Detail component and my component to the page. In my component, I update some fields of a record. After I save those field, I fire up the e.force:refreshView event. But the standard record detail component did not refresh to show the new value of those field. Is there any way to force to refresh the standard record detail component?

Here's the code:-

Component:

<div>
<force:recordView recordId="{!v.recordId}"/>
</div>
<div>...some input field... <ui:button label="Save" press="{!c.save}"/> 
</div> 

Controller:

save : function(component) {
    var action = component.get("c.saveInput");
    action.setParams({
        "objectName" : component.get("v.sObjectName"),
        "recordId" : component.get("v.recordId"),
        "postcode": component.get("v.postcode"),
        "city": component.get("v.city"),
        "state": component.get("v.state"),
        "country": component.get("v.country"),
        "street": component.get("v.street")
    });
    action.setCallback(this, function(action) {
        $A.get('e.force:refreshView').fire();
    });
    $A.enqueueAction(action);
 }
  • 1
    Can you share the code snippet? I tried at my end, it did refresh the record detail component with new values – Praveen Aug 3 '16 at 16:36
  • UI: <div><force:recordView recordId="{!v.recordId}"/></div> <div>...some input field... <ui:button label="Save" press="{!c.save}"/> </div> Controller save : function() { var action = component.get("c.save"); action.setCallback(this, function(action) { $A.get('e.force:refreshView').fire(); }); $A.enqueueAction(action); } After the callback, the record view did not refresh. The doc says this event will only be handled in the one.app container. I am not sure if my case will trigger the handler in the one.app container? – Ying Luan Aug 4 '16 at 0:13
  • are you telling the <force:recordView/> did not refresh with new values, when $A.get('e.force:refreshView') is fired? – Praveen Aug 4 '16 at 7:20
  • I assume I just need to fire the event and there is a predefined handler to automatically refresh the record view. I did not do anything to stop refreshing. – Ying Luan Aug 4 '16 at 23:35
1

You are not supposed to give same name to the apex controller's method and the function which is called on click. Also, you should pass event along with the component in the same. Please find the code below:-

Controller:-

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

Note save and apexSave.

The server-side action is also provided by the “c” value provider. This is the same value provider that provides the JavaScript controller event handler which handles the press event of the button and the init event. Because of this, you need to make sure that you do not name your Apex controller methods with the same name as your JavaScript controller methods. It’s easy to make the mistake of naming them same because it is natural to want to be consistent in naming.

Source:- Salesforce1 Lightning Components – Working with Controllers

You may use an aura handler to make sure that whether it has been refreshed successfully.

<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />
  • 1
    Yes. I did not use the same name in my original code. The input values are saved to the database, but just the refreshing did not work. – Ying Luan Aug 4 '16 at 23:30
  • 4
    My dear @YingLuan Then, kindly please post your "original code" instead of posting your "duplicate code"! It saves lots of time. Can you pls tell me how you're making sure that it's not being refreshed? – SE_User Aug 5 '16 at 4:15
  • 2
    Also @YingLuan it did work at my end with the above code. As I've edited the answer you may use an aura handler to make sure that whether it has been refreshed successfully. <aura:handler event="force:refreshView" action="{!c.isRefreshed}" /> – SE_User Aug 5 '16 at 4:28
  • I'm very sorry for the misleading codes and thanks a lot for your help. Just because that it has the characters limitations, so I deleted some codes at the beginning. I already updated the question with my codes. So the save operation will modify the address of the record and then fire the refresh event, but I did not see the new address showing. I tried the "isRefreshed" handler and add an alert there, I can see the alert showing but not the new address. – Ying Luan Aug 5 '16 at 6:41
  • And If I want to remove <force:recordView recordId="{!v.recordId}"/> from my component and drag the standard record detail view in the lightning experience record pages with my component as well. In the save function, if I fire the force:refreshView event, will it refresh the standard record detail component? – Ying Luan Aug 5 '16 at 6:46
0

You have'nt given component as a parameter in functions defined in the controller. But you are accessing component in your code.

Modify your code as follows.

save : function(component) { 
  var action = component.get("c.save"); 
  action.setCallback(this, function(action) {
    $A.get('e.force:refreshView').fire(); 
  }); 
  $A.enqueueAction(action); 
}
  • I do have component as a parameter in my code, just like what you provide. But the refreshing still does not work. – Ying Luan Aug 4 '16 at 6:05

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.