function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kanwalpreet SinghKanwalpreet Singh 

Apex how to check view is Salesforce Classic or Lightning.

Hi,

How i can check on controller if page is opened using 'Salesforce Classic' or 'Salesforce lightning' UI(for winter 16 release).

Thanks,
Kanwalpreet Singh
ShashankShashank (Salesforce Developers) 
I'm sure this will help you: http://bobbuzzard.blogspot.com/2015/11/context-is-everything.html
Anas LABRITIAnas LABRITI
with javascript you can do that :
    
        if(document.referrer.indexOf(".lightning.force.com") > 0){
            alert("welcome to lightning ");
        }else{
            alert("welcome to classic");
        }
narsavagepnarsavagep
FYI: This is now built in: https://developer.salesforce.com/blogs/isv/2016/04/introducing-ui-theme-detection-for-lightning-experience.html
gresy pritty 8gresy pritty 8
Nectar Card Activation offers cash discounts for shopping or payments. Nectar Card Activate Card
Shri RajShri Raj
By using Salesforce Theme you should be able to tell

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_useruitheme.htm
Shri RajShri Raj


Use these variables to identify the CSS used to render Salesforce web pages to a user. Both variables return one of the following values.
Valid values include:
Theme1—Obsolete Salesforce theme
Theme2—Salesforce Classic 2005 user interface theme
Theme3—Salesforce Classic 2010 user interface theme
Theme4d—Modern “Lightning Experience” Salesforce theme
Theme4t—Salesforce mobile app theme
Theme4u—Lightning Console theme
PortalDefault—Salesforce Customer Portal theme that applies to Customer Portals only and not to Experience Builder sites
Webstore—AppExchange theme

 

<apex:page>
    <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme2'}">
        // this is the old theme...
    </apex:pageBlock>

    <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme3'}">
       // this is the classic theme ...
    </apex:pageBlock>
</apex:page>

TobyKutlerTobyKutler
It should also be noted that there are some Salesforce bugs that cause the User.UITheme to return Theme3 when actually in Lightning. If that occurs you can use the UserPreferencesLightningExperiencePreferred on the User: 

example: 
List<User> users = [SELECT Id, UserPreferencesLightningExperiencePreferred FROM User WHERE Id = :UserInfo.getUserId() LIMIT 1];
        Boolean userInLightning =users[0].UserPreferencesLightningExperiencePreferred;