function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suresh SampathSuresh Sampath 

Current Appname in Lightning Experience

Hello,

I'm trying to determine the current app in Lightning mode. I tried both Javascript and Apex, but I was unable to get to retrieve the current appname.

In classic, I used the below which worked perfect!

document.getElementById("tsidLabel").innerText

This is not working in Lightning. We need page redirection based on the current application name. We tried in Apex too with "DescribeTabSetResult". But Apex retains the last application used or being used by the user and carries it over to Lightning. It ignores the user selection in Lightning and also the current displayed app in Lightning.

Any help in this regard would be greatly appreciated!!!

Thanks!!
Best Answer chosen by Suresh Sampath
Deepali KulshresthaDeepali Kulshrestha
Hi Suresh,

Please try the below code, it may be helpful to you.

public static String getAppName() {
    UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId = :UserInfo.getUserId() LIMIT 1];
    AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId = :userAppInfo.AppDefinitionId LIMIT 1];
    return appDefinition.Label;
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi Suresh,

Please try the below code, it may be helpful to you.

public static String getAppName() {
    UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId = :UserInfo.getUserId() LIMIT 1];
    AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId = :userAppInfo.AppDefinitionId LIMIT 1];
    return appDefinition.Label;
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
This was selected as the best answer
Suresh SampathSuresh Sampath
Hi Deepali,

Thanks. This works and yes this was helpful.