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
Shefali Vinchurkar2Shefali Vinchurkar2 

focusPrimaryTabByName method not working

Hi,

I have made a hyperlink to open a primary tab with the help of javascript (having openPrimaryTab  console method)embedded in the hyperlink function of salesforce formula field. The openPrimaryTab consoel method works fine without the focusPrimaryTabByName method, but the focusPrimaryTabByName doesn't work as expected

Below is the code used:

HYPERLINK("javascript:var html_doc = document.getElementsByTagName('head')[0];var js=document.createElement('script');js.setAttribute('type','text/javascript'); var custName ='"&  Customer__r.FirstName& ' '&Customer__r.LastName &"';js.setAttribute('src','/support/console/31.0/integration.js');html_doc.appendChild(js);js.onload= function() {sforce.console.focusPrimaryTabByName(custName, focusSuccess); var focusSuccess = function focusSuccess(result){if (result.success == true) {}else{sforce.console.openPrimaryTab(null, '/"& Customer__c &"' , true, '"&  Customer__r.Name &"',null,'"&  Customer__r.Name &"' );}} ;}; ", Customer__r.FirstName+' '+ Customer__r.LastName ,"_blank")
 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_focusprimarytabbyname.htm
<apex:page standardController="Case">

     <A HREF="#" onClick="testFocusPrimaryTabByName();return false">
         Click here to go to a primary tab by name</A> 

    <apex:includeScript value="/support/console/22.0/integration.js"/>
    <script type="text/javascript">
        function testFocusPrimaryTabByName() {
            //Get the value for 'myPrimaryTab' from the openPrimaryTab method
            //This value is for example purposes only
            var primaryTabName = 'myPrimaryTab';
            sforce.console.focusPrimaryTabByName(primaryTabName, focusSuccess);
        }
        
        var focusSuccess = function focusSuccess(result) {
            //Report whether going to the primary tab was successful
            if (result.success == true) {
                alert('Going to the primary tab was successful');
            } else {
                alert('Going to the Primary tab was not successful');
            }
        };
        
  </script>

</apex:page>

Let us know if this will help you