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.
Scenario 2: In other browser window, as a user I logged into Service app.
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.