+ Start a Discussion
Dave BerenatoDave Berenato 

Apex: OutputLink to open a new subtab in Lightning Console

I found some code in another post to make a Javascript button open in a new subtab inside the console:
 
<apex:includeScript value="/soap/ajax/26.0/connection.js"/>
    <apex:includeScript value="/support/console/26.0/integration.js"/>
    <script type="text/javascript">
        
        window.onload = function(){
           testOpenSubtab();
        };

        function testOpenSubtab() {
            //First find the ID of the primary tab to put the new subtab in
            sforce.console.getEnclosingPrimaryTabId(openSubtab);
        };

        var openSubtab = function openSubtab(result){
            var primaryTabId = result.id;
            sforce.console.setTabTitle('Add Rep Note');
        };
        
   </script>

I tried it for an apex:outputLink and it didn't work:
 
<apex:outputLink value="/{! record.id }" target="_blank"  id="theLink"><apex:outputField value="{! record.Name }"/>


The other question (https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000BTpTIAW) had code for the Javascript button but I don't know where to put that in the Visualforce Page.
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/28.0/integration.js")} 

var url = '/apex/Add_Rep_Notes?Id={!Account.Id}&isdtp=vw'; 

if (sforce.console.isInConsole()) { 
    srcUp(url);
} else { 
    window.open(url,'_blank');
}
I'm going to need this for several links on the page so I don't know how the "var url" would work.