2

I'm using following code in apex controller to get current appname user has logged into. But It always shows the last app name user has logged into.

For example: Scenario 1: As a user, I logged into Sales app in one browser window. In the logs, I get app name as Sales

Scenario 2: In other browser window, as a user I logged into Service app. In the logs, I get app name as Service

Scenario 3: When I go back to first browser window where Sales app is open and refreshed the page, it still shows Sales app in salesforce UI but in the logs I get app name as service because UserAppInfo always shows last app user has logged into. Would it possible to get current app name which is visible in salesforce UI in the logs not the last app name user has logged into. I need to show some data based on the App name visible in the salesforce UI. It should be updated when page is refreshed.

For example: show 'Sales Text' when logged into Sales App. show 'Service Text' when logged into Service App. How to make it work in scenario 3.

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];
String appName = appDefinition.Label;
System.debug('appName------->' + appName);

Any kind of help is appreciated.

3
  • I believe its showing correct data, as refresh cannot be treated as logged in flow. Commented Nov 27, 2020 at 9:27
  • 1
    Currently we are getting app name in apex controller. Is there any other way in JS to get current app name user has logged into. If we could get the value in JS controller then we could have app name in scenario 3(refresh page).
    – Rose
    Commented Nov 27, 2020 at 10:01
  • 1
    @Rose did you find a solution? I am having a similar issue.
    – Ward Wood
    Commented Feb 21, 2023 at 20:21

0

You must log in to answer this question.

Browse other questions tagged .