I used the visualforce example here

This however gives the code:

 <apex:includeScript value="/support/console/37.0/integration.js"/>
 <script type="text/javascript">
        function openPrimaryTab() {
               'http://www.example.com', true, 'example');

And then the link should be:

<A HREF="#" onClick="openPrimaryTab();return false">Open A Primary Tab</A>

Now I would like to have multiple links which open primary tabs. How can you create a general openPrimaryTab() function and then pass in the variables in the onClick function? I tried

sforce.console.openPrimaryTab(undefined, url, true, name);

And then in the link

<A HREF="#" onClick="openPrimaryTab(null,'{!URLFOR($Action.Account.View, Case.Account.Id )}',true,'Account');return false">{!Case.Contact.Name}</a></p>

But then the link does not work anymore. How can I set the right variables in order to make this work? Or is the only way to make different functions for every action you want to take? E.g. openAccount, openContact, etc?

1 Answer 1


Did you change your signature of openPrimaryTab to take parameters and verify that {!URLFOR($Action.Account.View, Case.Account.Id )} evaluates to a legal URL?

The following code works successfully for me.

<script src="/support/console/37.0/integration.js" type="text/javascript"></script>
function openPrimaryTab(v1, v2, v3, v4) {
    sforce.console.openPrimaryTab(v1, v2, v3, v4);
<A HREF="#" onClick="openPrimaryTab(null,'http://www.example.com',true,'example');return false">Open a primary tab</a>

Or even more simply I can just call the method directly from the anchor tag.

<script src="/support/console/37.0/integration.js" type="text/javascript"></script>
<A HREF="#" onClick="sforce.console.openPrimaryTab(null,'http://www.example.com',true,'example');return false">Open a primary tab</a>
  • That worked! I didn't know I had to add the parameters to the function as well as to sforce.console.openPrimaryTab. Works like a charm, thanks! Commented Aug 30, 2016 at 7:19
  • 1
    Yep, this is the the way it is for javascript and most programming languages as well. If you want to pass parameters to a function, then the function needs to be told how many to expect. This is done by changing what's called the 'function signature'.
    – Paul H.
    Commented Aug 30, 2016 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .