0

I have a custom button in console view that needs to open a new tab, that will overwrite the current tab. I do not want subtabs. My code is:

{!REQUIRESCRIPT("/xdomain/xdomain.js")} 
{!REQUIRESCRIPT("/soap/ajax/40.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/40.0/integration.js")} 
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js')} 
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js')}

$(document).ready(function(){ 
    var LeadId = '{!Lead.Id}'; 
    if (sforce.console.isInConsole()){ 
        sforce.console.getFocusedPrimaryTabId(closeSubtab2);
        sforce.console.openPrimaryTab(undefined, '/apex/LeadConvert?retURL='+ LeadId +'&id='+LeadId, true);
    }
    else{ 
        window.parent.location.href = '/apex/LeadConvert?retURL='+ LeadId +'&id='+LeadId; 
    } 
});

var closeSubtab2 = function closeSubtab(result) {
    var tabId = result.id;
    sforce.console.closeTab(tabId);  
};

I can't seem to get getFocusedPrimaryTabId() to pick up the Tab ID. My openPrimaryTab works great. I am not sure what I am doing wrong. I have basically copied this example: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getenclosingprimarytabid.htm . The only difference is that I am doing this in a custom button and not in a VFP. Any suggestions?

UPDATE:

Progress has been made. I found that it is getting tripped up on both primary tabs. When I remove the openPrimaryTab() method I am able to trigger the id and close the current tab. So now I need to figure out how to run both method without having them run into each other. Stay tuned!

1
  • Thank you @SantanuBoral! Hopefully I will have figured it out by then :) I will keep digging in the mean time!
    – Olivia
    Aug 9, 2017 at 22:33

1 Answer 1

0

So because there were two tabs involved, JS couldn't tell which tab to open and which one to close. I seperated the two tabs and came up with this code that works:

$(document).ready(function(){ 
    var LeadId = '{!Lead.Id}'; 
    if (sforce.console.isInConsole()){ 
       if(LeadId != null){
           var CMWindow = sforce.console.openPrimaryTab(undefined, '/apex/LeadConvert?retURL='+ LeadId +'&id='+LeadId, true); 
       }
        var id = sforce.console.getEnclosingPrimaryTabId();
        closeSubtab(id);
    }
    else{ 
        window.parent.location.href = '/apex/LeadConvert?retURL='+ LeadId +'&id='+LeadId; 
    } 
});

function closeSubtab(result) {
   var tabId = result.id;
   sforce.console.closeTab(tabId); 
};

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .