function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MOrtizMOrtiz 

Any ideas on how to avoid users from closing standard tabs in service console based on specific case criteria?

Khan AnasKhan Anas (Salesforce Developers) 
Hi,

I trust you are doing very well.​

Please refer to the below doc which might help you further with the above issue.​

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_disabletabclose.htm


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati
Are you using the classic or lightning ???

Classic code
 
<apex:page >
<html>
  <head>
    <title>Disable close Tab on Load</title>

    <!-- Service Console integration API library -->
    <script src="/support/console/44.0/integration.js"></script>

    <!-- Callback functions to handle tab events -->
    <script type="text/javascript">

      function displayResultsCallback(result){
        var resDiv = document.getElementById("eventResults");
        resDiv.innerHTML = JSON.stringify(result);
      }

      // For use within a tab's sidebar (you don't need tab ID)

      function testDisableTabCloseTrueWithoutId() {
        sforce.console.disableTabClose(true, false, displayResultsCallback);
      }

      function testDisableTabCloseFalseWithoutId() {
        sforce.console.disableTabClose(false, false, displayResultsCallback);
      }

      // For use anywhere (you need the tab ID)

      // Note: Your tab ID might be different than the one used here. 
      //       You can get the tab ID many different ways,
      //       including sforce.console.getEnclosingTabId().
      //       See the documentation for details.
      function testDisableTabCloseTrueWithId() {
        var tabId = window.prompt("Enter the tab ID","scc-pt-0");
        sforce.console.disableTabClose(true, tabId, displayResultsCallback);
      }

      function testDisableTabCloseFalseWithId() {
        var tabId = window.prompt("Enter the tab ID","scc-pt-0");
        sforce.console.disableTabClose(false, tabId, displayResultsCallback);
      }
     
    </script>
  </head>

  <body>
    <h1>Disable Tab Close Examples</h1>
    <br/><br/>
     
    <h2>API Callback Result</h2>
    <br/>
    
    <code><div id="eventResults" /></code>
    <br/>

    <h2>With No Tab ID</h2>
    <p>The tab ID will be auto-detected by context, or the event will fail.</p>

    <ul>
    <li><a href="#" onClick="testDisableTabCloseTrueWithoutId();return false;">
    Disable closing for the enclosing tab</a></li>

    <li><a href="#" onClick="testDisableTabCloseFalseWithoutId();return false;">
    Re-enable closing for the enclosing tab</a></li>
    </ul>
     
    <h2>With Tab ID Provided</h2>
    <p>When the event context doesn't have a detectable tab ID, you can 
    supply it yourself.</p>

    <ul>
    <li><a href="#" onClick="testDisableTabCloseTrueWithId();return false;">
    Disable closing for a specific tab (via tab ID)</a></li>

    <li><a href="#" onClick="testDisableTabCloseFalseWithId();return false;">
    Re-enable closing for a specific tab (via tab ID)</a></li>
    </ul>

  </body>
</html>
</apex:page>



Lightning code

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_disableTabClose.htm?search_text=Close
 
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <lightning:workspaceAPI aura:id="workspace" />
    <lightning:button label="Disable Close Focused Tab" onclick="{! c.disableCloseFocusedTab }" />
</aura:component>
 
({
    disableCloseFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.disableTabClose({
                tabId: focusedTabId,
                disabled: true
        })
        .then(function(tabInfo) {
            console.log(tabInfo);
        })
        .catch(function(error) {
            console.log(error);
        });
    })
    .catch(function(error) {
        console.log(error);
    });
    }
})

 
MOrtizMOrtiz
Lightning....thanks! I'll check this right away.
Raj VakatiRaj Vakati
The above compopnent will work for you  and you can add the component to the lilghtning record page and Set the component Visbility rules .. 

Based on the Visibility rules it will execute and disable the tab 
MOrtizMOrtiz
Create the component, controller and adding this in the page, but not having good luck with the execution. Any advice!? 
Raj VakatiRaj Vakati
Did you same code ?? give me code 
MOrtizMOrtiz
Yes. Same.
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <lightning:workspaceAPI aura:id="workspace" />
    <lightning:button label="Disable Close Focused Tab" onclick="{! c.disableCloseFocusedTab }" />
</aura:component>
 
({
    disableCloseFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.disableTabClose({
                tabId: focusedTabId,
                disabled: true
        })
        .then(function(tabInfo) {
            console.log(tabInfo);
        })
        .catch(function(error) {
            console.log(error);
        });
    })
    .catch(function(error) {
        console.log(error);
    });
    }
})

 
Raj VakatiRaj Vakati
Try this code 


Did you add this one to the lilghtninf record page ?? 
Can you see console logs what is coming ..? 
 
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <lightning:workspaceAPI aura:id="workspace" />
	    <aura:handler name="init" value="{!this}" action="{!c.disableCloseFocusedTab}"/>

 </aura:component>
 
 
 
 ({
    disableCloseFocusedTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.disableTabClose({
                tabId: focusedTabId,
                disabled: true
        })
        .then(function(tabInfo) {
            console.log(tabInfo);
        })
        .catch(function(error) {
            console.log(error);
        });
    })
    .catch(function(error) {
        console.log(error);
    });
    }
})

 
MOrtizMOrtiz
Ok.
Yes.
No. How can I see those logs?

 
Raj VakatiRaj Vakati
on browser Right click --> inspect Element --> Clic on Console tab 
MOrtizMOrtiz
aura_prod.js:599 HTTP-Based Public Key Pinning is deprecated. Chrome 69 and later will ignore HPKP response headers.
Raj VakatiRaj Vakati
Looks like..  I dnt see any issue in the code  ..If you added this to the lightning record page on console it must work 

 
MOrtizMOrtiz
That's what I expected. Thanks for your help. I'll keep the testing.
Raj VakatiRaj Vakati
Close this thread ! Glad that it helped