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

how to navigate to new primary tab automatically in Salesforce console?

using "sforce.console.openPrimaryTab" im opening a new primary tab in console and its a opeing a tab successfully. but i want to navigate automatically to new primary tab. is it doable in the console?

here is my code snippet.

<apex:page standardController="contact" extensions="XXXX" standardStylesheets="false">

<apex:includeScript value="/support/console/31.0/integration.js"/>
<script type="text/javascript">
 function OpenClientViewTab() {
 //Open a new primary tab with the ClientView home page in it
  sforce.console.openPrimaryTab(null, '/apex/CanvasAppPage?scontrolCaching=1&id={!contact.ID}', false,'ClientView', openSuccess, 'salesforceTab');
<apex:form id="myform"> 
<apex:pageblock >  
<apex:pageBlockButtons location="Top"> 
<apex:commandButton value="Client View" onclick="OpenClientViewTab();return false"  styleClass="buttonStyle" style="background:LightBlue;width:80px;float:Center;" /> 
<apex:pageMessages id="msgs"/>
Amit Chaudhary 8Amit Chaudhary 8

Please check below blog for more information in console related post:-

Include JS in VF page
<apex:includeScript value="/support/console/26.0/integration.js"/>

Write below Java Script code in VF page

function openTab(id, name) 
 if (sforce.console.isInConsole())
  sforce.console.openPrimaryTab(undefined, '/' + id + '?isdtp=vw', true, name);
 else = '/' + id;


Then use below link to open new record 
<a href="#" onclick="openTab('{!}''{!}'); return false;">{!Obj.customKey}</a>

Please let us know if this will help u

Amit Chaudhary
Thanks for your response..its not helpfull.  Your code and the code that i pasted does exactly the issue is not opening a primarytab. issue is once i open a new primarytab focus needs to be shifted to th newly opend tab not the current one. if you look at the screenshot below once i click the clientview button its opening the new
primarytab called vlientview but the focus is still on oldtab. i want the focus to be shifted to new tab. User-added image
Shefali Vinchurkar2Shefali Vinchurkar2
Hi KrForce,

Did you find a solution for this?
Bruce TollefsonBruce Tollefson
I'm assuming this is no longer an open question. However in your open primary tab function change the false to true:

  sforce.console.openPrimaryTab(null, '/apex/CanvasAppPage?scontrolCaching=1&id={!contact.ID}', true, 'ClientView', openSuccess, 'salesforceTab');

that should make it work