I have overriden new Account and Edit Account standard actions with some custom Lightning Components. On console navigation apps i want to close some tabs on Account save and then open a new tab to the record id just created. But this does not seem to work and i do not understand the reason why.
navigateTo: function(component, recId) {
//First determine whether navigation is Console or Standard
var workspaceAPI = component.find("workspace");
workspaceAPI.isConsoleNavigation().then(function(response) {
if (response) { //navigation is console
//Open a new tab with the record
workspaceAPI.openTab({
recordId: recId,
focus: true,
overrideNavRules: true
}).catch(function(error) {
console.log('error' +error);
});
workspaceAPI.getAllTabInfo().then(function(response) {
console.log(response);
for (var i=0; i<=response.length; i++) {
if ((response[i].title == 'Loading...') || (response[i].title == 'New Account') || (response[i].title == 'Νέος πελάτης') || (response[i].title == 'Φόρτωση...')) {
console.log(response[i].title);
workspaceAPI.closeTab({tabId: response[i].tabId});
}
}
})
.catch(function(error) {
console.log(error);
});
} else { //Standard navigation
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": recId
});
navEvt.fire();
window.setTimeout(
$A.getCallback(function() {
$A.get('e.force:refreshView').fire();
}), 2000
);
}
})
},
The issue is, new tab opens, the tabs i want to close get closed, but focus is not on the opened tab by my code. It is one tab left from the tab opened by my code. Any Ideas ?