How do I close a tab on Save in the Service console, but redirect the user when in Sales Cloud?

Specifically, when a user clicks a button from a related list in the Case page, I walk them through a wizard. When that wizard is done, I want the user's experience to be "finished", whatever that means. "Finished" in Sales Cloud means that they are back at the Case page. "Finished" in Service Console means that the subtab is closed, and they are looking at the Details subtab.

I have tried onclick, but that happens too soon. I have tried oncomplete, but that only happens on AJAX calls. This code is quite fragile and now is not the time for a refactor. I would love an Apex or VF method that mirrors sforce.console.isInConsole(), but I cannot find that.

How do I make this happen?

  • 1
    Pretty similar: salesforce.stackexchange.com/questions/29175/… Though it doesn't seem like Jim's solution is working for you. – Adrian Larson Jul 26 '16 at 19:35
  • Well, I didn't try using actionFunction, believe it or not, but I'm looking to close the tab, not send the user elsewhere. – Charles Koppelman Jul 26 '16 at 19:46
  • 1
    @AdrianLarson Yeah - just tried that path. The code that I'm working around is pretty fragile and I don't want to update it at the moment. – Charles Koppelman Jul 26 '16 at 19:58

If you just want a Boolean property to tell you if you are in the console, consider using an actionFunction or some similar mechanism to propagate that data from the client.


<apex:page controller="Demo">
        <apex:actionFunction action="{!flagConsole}" name="setConsole" rerender="none" />

        document.addEventListener('DOMContentLoaded', function() {
            if (typeof(srcUp) == 'function') { setConsole(); }


public with sharing class Demo
    public Boolean isInConsole { get; private set; }
    public Throwaway()
        isInConsole = false;
    public void flagConsole() { isInConsole = true; }
  • This is actually terrific for other cases. +1! (yes, 1 factorial) But... Apex can't close a tab, so... how does this help? I guess the actionFunction can rerender an actionRegion which declares a javascript function in it? Or perhaps the commandButton can be rerendered? – Charles Koppelman Jul 26 '16 at 20:28
  • Oh you just said in your OP I would love an Apex or VF method that mirrors sforce.console.isInConsole(), but I cannot find that. Let's see now... – Adrian Larson Jul 26 '16 at 20:31
  • Ah. The goal of that was to use a rendered attr on the commandButton – Charles Koppelman Jul 26 '16 at 20:34

I am facing similar conundrum now and perhaps a decent solution would be redirecting to a dummy Visualforce page that closes itself.

This way it works for both, save and cancel buttons. You still need to intelligently route to either VF page when in console and to parent record id when in classic (using Adrian's suggestion).

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.