[SalesForce] Lightning service console refresh tab

We are trying to refresh a parent tab after an action is taken using the JavaScript API for lightning service console.

Here is the controller code:

var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(tabInfoResponse) {
            console.log('Response from getting tab info.');
            console.log(tabInfoResponse);
            workspaceAPI.getTabInfo({
                tabId: response.parentTabId
            }).then(function(parentTabInfoResponse) { 
                console.log('Response from getting parent tab.');
                console.log(parentTabInfoResponse);
                var myCaseID = parentTabInfoResponse.recordId;
                workspaceAPI.closeTab({
                    tabId: parentTabInfoResponse.tabId
                }).then(function(closeTabResponse) {
                    console.log('Response from closing tab.');
                    console.log(closeTabResponse);
                    console.log('about to open this tab caseId.');
                    console.log(myCaseID);
                    workspaceAPI.openTab({
                        recordId: myCaseID,
                        focus: true
                    }).then(function(newTabResponse) {
                        console.log('Response from opening tab.');
                        console.log(newTabResponse);
                        workspaceAPI.getAllTabInfo().then(function(allTabResponse) {
                            console.log('Response from getting all tab information.');
                            console.log(allTabResponse); 
                        })
                        //workspaceAPI.focusTab({tabId : newTabResponse});
                    })
                })
            })
        }).catch(function(error) {
            console.log(error);
        });

So everything works fine until this line: workspaceAPI.focusTab({tabId : newTabResponse});

Here is the output from chrome console:

Response from getting tab info. {tabId: "ctab0_1", url: "https://...
Response from getting parent tab. {tabId: "ctab0", url: "https://...
Response from closing tab. true
about to open this tab caseId. 50021000002SAORAA4
Response from opening tab. ctab0
Response from getting all tab information. []

How is is possible that we opened a new tab for the case, yet immediately afterwards the response from getting all tab information is an empty array?

Is there an easier way to refresh a tab in Lightning Service Console without a hard refresh?

Best Answer

I figured it out!, the $A.get('e.force:refreshView') statement was what I was looking for, but I am still not sure why the response from getting all tab information is an empty array in the above question - that may be something to look into...

workspaceAPI.getFocusedTabInfo().then(function(response) {
                        var focusedTabId = response.tabId;
                        component.set("v.recordId",caseId);
                        workspaceAPI.closeTab({tabId: focusedTabId});
                        workspaceAPI.openTab({
                            recordId: caseId,
                            focus: true
                        }).then(function(response) {
                            workspaceAPI.focusTab({
                                tabId: response
                            });
                            setTimeout(function(){
                                $A.get('e.force:refreshView').fire();
                            }, 1000); 

                        })
                        .catch(function(error) {
                            console.log(error);
                        });

                    });
Related Topic