4

In Spring 18, UserInfo.getUiThemeDisplayed() would return Theme3 when it was called by a lightning component in classic. In summer 18, it has now started returning Theme4d. This is a problem, as we need to detect if the user is in classic mode or lightning (we redirect pages differently depending on this).

There are no notes in the documentation for this change, so I believe this is a bug on salesforces part.

Has any one else noticed this? Has salesforce provided an alternative method of determining if the user is in classic or lightning? Alternatives are available. See comments below.

P.S - This definitely worked in Spring 18 and has only stopped working in Summer 18

Edit

I have a lightning component that needs to redirect the user when the user clicks the button. If the user is in lightning experience, then we use the redirect event to redirect the user. If classic, we use window.location.href.

To detect if the user is in classic or lightning experience, we make a call to an apex controller UserInfo.getUiThemeDisplayed() . This used to return Theme3 in Spring 18 when on classic and now returns Theme4d.

Edit

Some one has raised a case with Salesforce. https://success.salesforce.com/issues_view?id=a1p3A000000ETV0QAO

  • 2
    This is especially infuriating given that they referenced this solution at TrailheaDX... – SFDC Neuf May 22 '18 at 20:08
1

Can I assume you're using Lightning Out to display this component in Visualforce?

Perhaps a more robust way to handle this is, have Visualforce pass a parameter to the Lightning component indicating it's coming from a Classic VF context. Then the component knows for sure.

  • Yes, we're using Lightning out. Passing a parameter is one of the solutions we've come up with if we can't find a solution to the api returning the correct theme. Thanks – Xander May 17 '18 at 11:35
0

I suppose there is a bug in UserInfo.getUiThemeDisplayed(). Fortunately, in Summer '18, the theme is directly accessible from the Visualforce page. Call UITheme.getUITheme() to return the theme in the VF page directly. Then you can pass it as a parameter to the component. While the bug you reference is frustrating, this should be a better way to retrieve the theme to begin with.

See the documentation here. (Note: use UITheme.getUITheme(), not UITheme.getUITheme - there is a typo.)

Example:

$Lightning.createComponent(
    "C:MyComponent"
    , {
        isLightning: UITheme.getUITheme() === "Theme4d"
    }
    , "renderDiv"
    , function (component) {}
);

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.