4

Is there any programmatic way - Apex, Lightning, URL, etc - to switch a user from being in one Lightning App to another? E.g. the equivalent of the user clicking the upper-left dots menu, choosing something in App Launcher, and ending up in that app?

2 Answers 2

2

I have done some debugging using lightning inspector and found out what event is fired when we click on a app in app launcher.

So event fired is force:switchApp with parameters

    var appEvent = $A.get("e.force:switchApp");
    appEvent.setParams({
        "tabsetId": "02uU0000000DtzAIAS",
        "startUrl": "/one/one.app#/sObject/02uU0000000DtzAIAS"
    });
    appEvent.fire();

One thing I was not able to find out how to get tabsetid. TabsetId is of sobjectType TabSet. But TabSet cannot be queried. :( I queried appDefination and tabDefination but no luck there also. So only way to find tabsetId is using lightning inspector and then go to event log and find app id.

Edit

As suggested by Charles in comments we can use tooling api to get app id using

SELECT AppId, Label, Active, SortOrder FROM MenuItem WHERE MenuType = 'AppSwitcher'
5
  • 1
    That's a good find Manjot. :) Just a caveat, e.force:switchApp is not documented and might just stop working without notice. I have happened before so should not be relied on as a concrete solution, Oct 31, 2018 at 15:10
  • Yes, agree don't use this solution until absolutely necessary or sales force comes with documented solution Oct 31, 2018 at 15:15
  • Thanks for the insight! Possible workaround to obtain the app ID programmatically. Create a permission set and assign it only one thing: The one app you want to switch to. Now you can query SetupEntityAccess and you will see a record with SetupEntityType = TabSet, and SetupEntityId starting with 02u.
    – Charles T
    Nov 1, 2018 at 1:24
  • 1
    Also you can query these 02u IDs via Tooling API as such: SELECT AppId, Label, Active, SortOrder FROM MenuItem WHERE MenuType = 'AppSwitcher'. Try in Developer Console with the Use Tooling API box checked.
    – Charles T
    Nov 1, 2018 at 1:29
  • I guess this could be a whole other question, but did you find any way to detect which Lightning app a component is running in?
    – Charles T
    Nov 5, 2018 at 14:14
2

In case someone finds this and doesn't know about recent developments: you can navigate to Salesforce apps using Page References with aura and lwc with the lightning/navigation component.

You can also just navigate to a url e.g. https://myInstance.lightning.force.com/lightning/app/c__MyCustomApp or https://myInstance.lightning.force.com/lightning/app/standard__LightningSales.

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.