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, 2018 at 16:22
  • @RahulSharma, which version of apex class and visualforce page should I use? Mar 1, 2018 at 13:29
  • try upgrading or downgrading to different versions maybe in between 37.0 to 42.0
    – Raul
    Mar 1, 2018 at 15:16
  • @RahulSharma, I tried changing the version from 28-42 but it did not work. Mar 5, 2018 at 9:06

1 Answer 1


"{!$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.

  • 1
    This appears to behave inconsistently in our org. Some pages I can use a customController and Theme4 is returned for Lightning. Other times I not only have to use a standard controller and extension, but have to override the 'View' button/action to get my vf page to display something other than Theme3 in Lightning.
    – rmarq423
    Feb 17, 2021 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .