0

I have a button "Create Activity" in a lightning component (say LC1) on the case lightning record page. When I click that button, an another lightning component (say LC2) opens as a sub tab with some fields to be filled. Once all details are entered, save (Used Lightning Data Service) button is clicked.

Issue here is, I need to close the LC2 which in turn should refresh the LC1 so that the related list in LC1 will display the created record from LC2, which is not happening.

I have tried 2 ways:

  1. window.location.reload();

    • When I use this approach, LC2 is getting closed, the browser tab is refreshed but the LC2 is opening again and this should not happen.(Not sure why this is happening)
  2. workSpaceAPI.refreshTab

    • When I use this, LC2 is closed but LC1 is not refreshed. My doubt here is, once the LC2 is closed, does LC1 consider the refresh request from the closed LC2?

saveActivity : function(component, event, helper){
        console.log('field values'+JSON.stringify(component.get("v.simpleNewActivity")));
    component.find("activityRecordCreator").saveRecord(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            // record is saved successfully
            var resultsToast = $A.get("e.force:showToast");
            resultsToast.setParams({
                "title": "Saved",
                "message": "The record was saved."
            });
            resultsToast.fire();
            var workspaceAPI = component.find("workspace");
           //caseTabId is the source Tab Id
            var caseTabId = component.get("v.caseTabId");
            workspaceAPI.getFocusedTabInfo().then(function(response) {
                var focusedTabId = response.tabId;     
                //window.location.reload(); 
                workspaceAPI.refreshTab({
                    tabId:caseTabId, 
                    includeAllSubtabs: true
                });
                workspaceAPI.closeTab({tabId: focusedTabId}); 
            }) 
            .catch(function(error) {
                console.log(error);
            });  
        } else if (saveResult.state === "INCOMPLETE") {
            // handle the incomplete state
            console.log("User is offline, device doesn't support drafts.");
        } else if (saveResult.state === "ERROR") {
            // handle the error state
            console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
        } else {
            console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
        }
    });
}
0

You can capture the lighting data service event created by the second component in the first component by adding the below aura handler to the first component

<aura:handler event="force:refreshView" action="{!c.init}"/>

where the action tag in the handler calls the javascript function that calls the apex class that gets the data

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.