I am trying to automatically close a tab in Salesforce after X amount of time. I am doing this through a lightning cmp that is placed onto a record page. The code works, but immediately closes the tab. I'm currently testing with a 9 second wait period. I've done this in JS before by placing the time time after the window location and was thinking the same thing would apply here, but it would appear I am doing something wrong.
Controller:
({
onChatEnded: function(cmp, evt, helper) {
/*var conversation = cmp.find( "conversationKit" );
var recordId = evt.getParam( "recordId" );
console.log( "recordId:" + recordId );*/
var workspaceAPI = cmp.find( "workspace" );
workspaceAPI.getFocusedTabInfo().then( function( response ) {
var focusedTabId = response.tabId;
console.log( 'Focused Tab is ' + focusedTabId );
window.setTimeout($A.getCallback(function(){
workspaceAPI.closeTab( { tabId: focusedTabId } ); }, 900000));
})
.catch(function( error ) {
console.log( 'Error is' + JSON.stringify( error ) );
});
}
})
*updated code to my current version. The code saves without error, but the cmp doesn't seem to be respecting the setTimeout