I'm trying to detect on a visualforce page that is the page opened in a classic or Lightning view in Salesforce. For this I'm using "$User.UITheme" and "$User.UIThemeDisplayed" on the visualforce page and it is always return "Theme3". Also, when I use the UserInfo.getUiThemeDisplayed() method in the controller and display on the page it shows "Theme3" instead of "Theme4d" even if I'm in the lightning experience.

Here is the controller code:-

public with sharing class CheckUITheme {

    public String themeViewed{get;set;}

    public CheckUITheme(){
        themeViewed = UserInfo.getUiThemeDisplayed();

Here is the Visualforce page code:-

 <apex:page controller="CheckUITheme"> 
  <h1>Congratulations</h1> This is your new Page
>>>>>>>>{!themeViewed}>>>>>>>>> {!$User.UITheme} {!$User.UIThemeDisplayed}  

and the output which I get is :-

Congratulations This is your new Page >>>>>>>Theme3>>>>>>>>> >>>>>>>Theme3>>>>>>>>> Theme3 Theme3

What wrong m I doing here or is there a bug in the Salesforce method?

  • Tried changing versions of apex class and page? – Raul Feb 28 '18 at 16:22
  • @RahulSharma, which version of apex class and visualforce page should I use? – Jitesh Goel Mar 1 '18 at 13:29
  • try upgrading or downgrading to different versions maybe in between 37.0 to 42.0 – Raul Mar 1 '18 at 15:16
  • @RahulSharma, I tried changing the version from 28-42 but it did not work. – Jitesh Goel Mar 5 '18 at 9:06

"{!$User.UITheme} {!$User.UIThemeDisplayed}", worked for me on the visualforce page when I used it in a inline visualforce page with the Standard controller and when I previwed the page as a visualforce page only it does not work. Strange but, the theme detection works for standard controllers on a inline VF page.

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.