March 10, 2021

How to lock and unlock tab in Salesforce Classic Console App?

Sample Code:

To lock the record:
var jq = document.createElement('script');
jq.src = 'https://c.na172.visual.force.com/support/console/44.0/integration.js';
document.getElementsByTagName('head')[0].appendChild(jq);
var disableBool;
function showTabId( result ) {
    
    console.log( JSON.stringify( result ) );
    console.log( 'Enable Bool value is ' + disableBool );
    sforce.console.disableTabClose( disableBool, result.id );
    
}
disableBool = true;
sforce.console.getFocusedPrimaryTabId( showTabId );


To unlock the record:
var jq = document.createElement('script');
jq.src = 'https://c.na172.visual.force.com/support/console/44.0/integration.js';
document.getElementsByTagName('head')[0].appendChild(jq);
var disableBool;
function showTabId( result ) {
    
    console.log( JSON.stringify( result ) );
    console.log( 'Enable Bool value is ' + disableBool );
    sforce.console.disableTabClose( disableBool, result.id );
    
}
disableBool = false;
sforce.console.getFocusedPrimaryTabId( showTabId );
 

Note:
Change the instance name(na172) if you face any cross-origin errors.

No comments:

Post a Comment