12

Has anyone figured out a way to differentiate between Lightning Desktop and Salesforce1?

There are mechanisms to detect if a user is using Lightning Desktop / Salesforce1 vs Salesforce Classic (Aloha). See here for a Javascript solution.

I know officially (same link - see 'Limitations of Detecting sforce.one') there is no supported mechanism yet. I've also read about the Visualforce workaround that is out at the moment.

I want to know specifically a front end way to tell the two interfaces apart.

Thanks Nelson

2
  • 3
    does user-agent help here by any chance ? Commented Oct 13, 2015 at 14:02
  • Thanks I'm looking into it. I think there's a problem with certain devices that don't send a standard 'token' in the user agent so that we can easily tell what device it is. One I can think of is the Kindle Fire HDX. Here's a good resource pointing out common User Agent strings for Tablets and Mobile : developer.mozilla.org/en-US/docs/… Commented Oct 13, 2015 at 15:22

3 Answers 3

11

With Spring 16 release, we are getting new values added to the existing $User.UITheme Global variable and to the UserInfo.getUiTheme() method which will help us to identify the current user's UI mode.

here's the list of possible values

  • 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 — Salesforce1 mobile Salesforce theme
  • PortalDefault — Salesforce Customer Portal theme
  • Webstore — Salesforce AppExchange theme

hopefully we can use this in Workflows, Validations, Formulas, Apex & Visualforce..

Official Reference

2
  • Many Thanks Vamsi. I'll select this as the correct answer as there is an API opened up to developers now. Commented Feb 9, 2016 at 13:57
  • 1
    It is worth being aware that there is a known issue with Salesforce Classic in mobile. The Theme displayed shows as Theme4t rather than Theme3, as would be expected: success.salesforce.com/issues_view?id=a1p3A000000jl1UQAQ
    – Bigears
    Commented Sep 22, 2016 at 14:48
4

Until there's an official Salesforce way I'm going with a JS solution to detect if the user is using a mobile device. I'm using JS to find the user agent and match against the keyword 'Mobi':

var isMobile = function() {
     //using regex here so developers can add more keywords if needed
     return navigator.userAgent.match('(Mobi)') ? true : false;
}

If the user is using a browser on a mobile device, they will be navigated to Salesforce1. Also the User Agent for the Salesforce1 App (Android and iOS) has 'SalesforceMobileSDK'.

Thanks Vamsi Krishna for pointing me in the right direction.

2
  • 1
    glad u got it working.. does it cover tablets as well ?? Commented Oct 16, 2015 at 1:58
  • If the tablet has Mobi in the user agent then yes. You could add 'Tablet' to the regex : '(Mobi|Tablet)' . I found Mobi on its own worked well. Phone's I tested with: Android, iPhone and Windoze. Tablets : Android, iPad and Surface. Everything seemed in sync with what Salesforce is doing (The Surface navigated to Lightning experience and isMobile returned false). Commented Oct 16, 2015 at 10:15
1
 public static string isLightningExperience()
 {
        boolean isLightningExperience = false;
        string id = UserInfo.getUserId();
        for (User u: [SELECT Id, UserPreferencesLightningExperiencePreferred FROM User WHERE Id =: id LIMIT 1])
        {
            isLightningExperience = u.UserPreferencesLightningExperiencePreferred;
        }
        return string.valueOf(isLightningExperience);
 }

the value of the field UserPreferencesLightningExperiencePreferred in the object user change when the user interface switch. if UserPreferencesLightningExperiencePreferred is ture => Lightning Desktop , if false => Classic Desktop

3
  • 1
    Just putting code will not help. Please explain how this resolves the issue.
    – Reshma
    Commented Mar 1, 2017 at 10:19
  • the value of the field UserPreferencesLightningExperiencePreferred in the object user change when the user interface switch. if UserPreferencesLightningExperiencePreferred is ture => Lightning Desktop , if false => Classic Desktop Commented Mar 27, 2017 at 10:22
  • Please use edit to update your answer and not put it as a comment
    – Reshma
    Commented Mar 27, 2017 at 10:27

You must log in to answer this question.

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