html code

Distinguish between the LWC applications being used by the user.

I am developing a custom Account LWC right now and we have to Apps for different Regions. For that I have created two Apps to do this. The Problem is that the some Users are working in both Apps and also they could have to Tabs open, one for the Region A and one for Region B. With this we cannot save a Information on the User to check which App is active right now.

Before we tried to use the Object UserAppInfo in combination with AppDefinition but this wasn’t reliable enough for our Use Case.

That’s why I have created a LWC to save the current App in the Session Storage for the current Tab and I put this LWC on the Home Page where the User lands when the App is changed. This was working fine when testing some things. But I discovered a Problem: When you open the Account Page in a new Tab, the current Session Value is not transferred, which is the normal behavior.

I also saw while investigating that Salesforce already saves an Entry in the Session Storage called appContextId with the current App. I would like to use this but I’m unable to use it while I’m in the Context of the LWC. When testing it directly in the Console of the Browser, I’m able to get it.

My Question is now if there is a way to access a Standard Value from the Session Storage which is not assigned to the current Namespace of the LWC I’m in or if there is another Solution I can use to save it when opening the Account in a new Tab.

Right now I have something like this:

LWC:

import getCurrentApp from "@salesforce/apex/LtngUtilities.getCurrentApp";

import { LightningElement, api } from "lwc";

export default class LtngTriluxCurrentApp extends LightningElement {

    @api sAppName;

    async connectedCallback() {

        const oApp = await getCurrentApp({ appName: this.sAppName });

        sessionStorage.setItem("appName", oApp);

    }

}

Apex:

@AuraEnabled

public static String getCurrentApp(String appName) {

    AppDefinition appDefinition = [

            SELECT DurableId, DeveloperName, Label

            FROM AppDefinition

            WHERE DeveloperName = :appName

            LIMIT 1

        ];

    return JSON.serialize(appDefinition);

}