I've just used openSubtab() successfully in a custom button to load a record in a new subtab in the Service Console, using the result[0].id returned from sforce.connection.create([record]).

I've also built some Custom Console Components as well that display lists of records in an apex:pageBlockTable that I would like to have the same functionality as a related list, to navigate to the individual records in their own subtabs, to save the user a click.

<apex:column width="50px" id="caseLink" headerValue="{!$ObjectType.case.fields.casenumber.label}" >
    <apex:outputLink value="/{!historyItem.Id}" onclick="myOpenSubtab({!historyItem.id})" >{!historyItem.caseNumber}</apex:outputLink>

If I wrap sforce.console.openSubtab() in a function myOpenSubtab(Id listItemId) that takes that {!historyItem.id} as a parameter, calling that function from the OnClick event of the link should do the trick, no?

I'm opening Cases in particular, so I created a Case-specific function for the purpose:

 <script type="text/javascript">
    function openCaseSubtab(id caseId) {

        var openCase = sforce.console.getEnclosingPrimaryTabId(function(response) {
            var primaryTabId = response.id;

            // create a Case detail url (with a default value of 500 (Case prefix))
            var url = "{!URLFOR($Action.Case.View, '500')}";

            // replace the Id with the Case.Id passed in to the function 
            url = url.replace("500", caseId);

            /* Define other parameters for openSubtab() */
            var isActive = true;
            var tabLabel = null;
            var subtabId = null;

            // Call the standard openSubtab method with the current Case's info
            var newCaseTab = sforce.console.openSubtab(
                primaryTabId, url, isActive, tabLabel, subTabId);



I'm getting the following errors:

Uncaught SyntaxError: Unexpected token ILLEGAL

Uncaught ReferenceError: srcUp is not defined

Anyone see anything obvious as far as how my function is implemented? In the custom button, everything is contained within this

sforce.console.getEnclosingPrimaryTabId(function(response) { ... }

and a new function per se is not required. The openCase and newCaseTab variables were not necessary in the button implementation either; I added them here to prevent Compilation errors that prevented the page from saving.

1 Answer 1


Issue 1: Using a Visualforce expression

Would you try updating your onclick attribute? Right now it's written:


I think it should be:


The reason is that the Visualforce expression is evaluated as text and then injected into the HTML as the value, without any quotes. You need to manually add the quotes to delineate the value from the rest of the function call syntax.

Issue 2: JavaScript function declaration

Would you remove the id text from your declaration of openCaseSubtab()? Right now you're declaring the JavaScript function as if you were declaring a method in Apex, which is incorrect. JavaScript function parameters are not typed (meaning you don't specify that the parameter needs to be an Id or a List<Case>). Your function declaration should look like this:

function openCaseSubtab(caseId) {
  • The link output looks better now when I hover over the link (javascript:srcUp('https%3A%2F%2Fcs8.salesforce.com%2F500L0000005ngOMIAY%3Fisdtp%3Dvs'); if you must know), and the error has changed to Uncaught ReferenceError: openCaseSubtab is not defined, and Uncaught ReferenceError: srcUp is not defined. I'm hoping that perhaps once the function is recognized the srcUp will resolve itself..? Mar 19, 2015 at 12:56
  • There's another error right above those two: GET test.salesforce.com/javascript/1426673431000/sfdc/source/… 404 (Not Found) That's probably relevant. Mar 19, 2015 at 13:02
  • onclick="openCaseSubtab('{!historyItem.Id}')" is the actual syntax, now, with the same spelling/case as the function... which makes 'openCaseSubtab is not defined' particularly annoying. I'll recheck the function for punctuation errors. ('myOpenSubtab' was a placeholder name) Mar 19, 2015 at 13:16
  • <script src="/support/console/33.0/integration.js" type="text/javascript"></script> precedes the <script></script> that contains the function, followed by a <style></style> and then the page details. Just in case ordering has anything to do with unrecognized function. Mar 19, 2015 at 13:25
  • @DuncanStewart I edited my answer to address another issue with the JavaScript code, where you delcare the function with an extraneous id in front of caseId.
    – Marty C.
    Mar 19, 2015 at 20:08

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.