I use this code to closeTab from Visualforce in Lightning Experience:

function closeFocusedTab() {
        logToBrowserConsole('Executing closeFocusedTab function');
        sforce.console.getEnclosingTabId(function(enclosingTabResult) {
            if (enclosingTabResult.id) {
                sforce.console.setTabUnsavedChanges(false, function() {
                    sforce.console.disableTabClose(false, enclosingTabResult.id, function(disableTabCloseResult) {
                        if (disableTabCloseResult.success) {
                            sforce.console.closeTab(enclosingTabResult.id, function(closeTabResult) {
                                if (closeTabResult.success) logToBrowserConsole('Tab successfully closed');
                                else logToBrowserConsole('ERROR - Failed to close tab, ' + closeTabResult.error);
                        else logToBrowserConsole('ERROR - Failed to unlock the enclosing tab, ' + disableTabCloseResult.message);
            else logToBrowserConsole('ERROR - Failed to get the enclosing tab id');

This code works when I land into this Visualforce from another Visualforce page or a Lightning Component but it doesn't work if I put that Visualforce as Override of a standard button. I got this error:

enclosingTabResult = {success: false, errorMessage: "Error: Invalid request."}

Could someone explain me how happened this? I think a workaround could be to open a technical page that open this one, but I want to find a more clear solution.

Thanks for any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.