<apex:includeScript value="/support/console/42.0/integration.js"/>

<script type="text/javascript" >

    function testOpenSubtab() {
        //First find the ID of the primary tab to put the new subtab in


    var openSubtab = function openSubtab(result) {
        //Now that we have the primary tab ID, we can open a new subtab in it
        var primaryTabId = result.id;
        console.log('primaryTabId '+primaryTabId);
        sforce.console.openSubtab(primaryTabId , 'www.google.com', false, 
        'Order App',null);
        console.log('**  openSubtab : '+openSubtab);


 function setFocusSubTab(){

var focusSubTab = function focusSubTab(result){

sforce.console.focusSubtabById(previousOnload); var previousOnload = window.onload; // Script runs automatically when page is finished loading window.onload = function(result) { if (previousOnload) { sforce.console.setTabTitle('Case:'+'{!Case.CaseNumber}'); setFocusSubTab(); }



<apex:pageBlock >
    <apex:form >
        <body >
           <apex:detail subject="{!case.Id}" />


  • 1
    Welcome to Salesforce Stack Exchange. To be productive here, you need to include more than a title and a large code paste. What exactly is not working in your code? Which lines? What errors are shown, or what bad behavior? Consider including only relevant code, not everything. How to Ask is a good resource to learn how to frame a successful, answerable question. – David Reed Apr 12 '18 at 15:00
  • Thank you! Code is working fine but the problem is it has two subtabs,i need to set the focus onto first tab but it is always changing the focus to the second tab. – Salesforce User Apr 12 '18 at 15:11

Merge fields generally need to be in quotes:

var caseid = "{!case.id}";

As an aside, you can use merge fields directly in a string:

sforce.console.setTabTitle('Case: {!Case.CaseNumber}');

You should always consider what the JavaScript source would look like as if the merge field were literally replaced in to the source (which is what happens).

| improve this answer | |
  • Thank you for your reply,but it was working fine the single quotes as well,the problem is i'm unable to set the focus on tab1 . – Salesforce User Apr 12 '18 at 15:15
  • @SalesforceUser Why not? Are you getting an error? Without more details, we can only go on what you've given us, which was already-broken code. – sfdcfox Apr 12 '18 at 15:24
  • No error, Actually it's not changing the tab sforce.console.focusSubtabById(openSubtab); so i've written the function function testFocusSubtabById() { //Get the value for 'scc-st-0' from the openSubtab method //This value is for example purposes only console.log('*subtabId tabid:'+subtabId); sforce.console.focusSubtabById(subtabId); } and on page load I've called the method when i do that its not opening the subtab sforce.console.openSubtab(primaryTabId , 'www.google.com', true, 'Order App',null); – Salesforce User Apr 12 '18 at 15:33
  • 1
    @SalesforceUser The callback should give you an error object as well. What does it say? – sfdcfox Apr 12 '18 at 15:42
  • 1
    @SalesforceUser Again, did you check the properties of "result"? Is there an error message? – sfdcfox Apr 12 '18 at 16:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.