1

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?

3
  • 1
    Pretty similar: salesforce.stackexchange.com/questions/29175/… Though it doesn't seem like Jim's solution is working for you.
    – Adrian Larson
    Commented Jul 26, 2016 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. Commented Jul 26, 2016 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. Commented Jul 26, 2016 at 19:58

2 Answers 2

1

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.

Markup

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

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            if (typeof(srcUp) == 'function') { setConsole(); }
        });
    </script>
</apex:page>

Controller

public with sharing class Demo
{
    public Boolean isInConsole { get; private set; }
    public Throwaway()
    {
        isInConsole = false;
    }
    public void flagConsole() { isInConsole = true; }
}
3
  • 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? Commented Jul 26, 2016 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
    Commented Jul 26, 2016 at 20:31
  • Ah. The goal of that was to use a rendered attr on the commandButton Commented Jul 26, 2016 at 20:34
0

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).

You must log in to answer this question.

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