2

I saw in Ideas for Salesforce that currently there is no such feature that denies users from switching back to Salesforce Classic once they are using Lightning Experience. This lead to me to try and achieve that requirement. I came to know that there is a field on User, named "UserPreferencesLightningExperiencePreferred", on User, which becomes true when we are using Lightning Experience. So I created a Process Builder that runs whenever a user is updated, This process builder eventually calls a flow which checks the value of UserPreferencesLightningExperiencePreferred field, and if that is set to false, it turns it back to true.

This was created keeping in mind that in such a way, a user will not be able to switch back to Classic from Lightning Experience.

But, that process builder didn't behave as desired.

Additionaly, I created a before update trigger on User object whose code is as follows:

trigger UserTrigger on User (before update) {
    if(Trigger.isBefore && Trigger.isUpdate) {
        UserTriggerHandler objUserTriggerHandler = new UserTriggerHandler();
        objUserTriggerHandler.onBeforeUpdate(Trigger.new);
    }
}

And the Apex Handler is as follows :

public with sharing class UserTriggerHandler {
    Set<Id> setCriteriaUserId = new Set<Id>();
    List<User> lstUser1 = new List<User>();
    public void onBeforeUpdate(List<User> lstUser) {
        for(User user : lstUser){
            if(user.Profile.Name =='Standard User'){
                setCriteriaUserId.add(user.ID);
            }
        }
        for(User user : [Select 
                                        Id,
                                        UserPreferencesLightningExperiencePreferred, 
                                        ProfileId 
                                From 
                                        User u
                                Where
                                        Id IN :setCriteriaUserId
                                        ]) {
                                        System.debug('Debug Log for User Preference'+user.UserPreferencesLightningExperiencePreferred);
                                            if(user.UserPreferencesLightningExperiencePreferred = false){
                                                user.UserPreferencesLightningExperiencePreferred = true;
                                              System.debug('Debug Log for User Preference Final'+user.UserPreferencesLightningExperiencePreferred);   
                                            }
                                        }
    }
}

But even that is not working.

Can anyone please help and suggest me some ways of how can we achieve the same?

4 Answers 4

5

In the Lightning now tour, the PMs said this is coming with the Summer17 release, where classic access can be removed w a permission set.

It's now listed on the roadmap doc here

https://help.salesforce.com/articleView?id=lex_roadmap.htm&language=en_US&type=0

Select which Lightning Experience users can access Salesforce Classic

screenshot of roadmap

2

Since your User trigger is in the before update context, I think you should be able to do something like this:

trigger UserTrigger on User (before update) {
    if(Trigger.isBefore && Trigger.isUpdate) {
        for(User updatedUser : Trigger.new) {
          if(updatedUser.Profile.Name == 'Standard User' && !updatedUser.UserPreferencesLightningExperiencePreferred) {
            updatedUser.UserPreferencesLightningExperiencePreferred = True;
          }
        }
    }
}

Though as crmprogdev mentioned, even if this does work the User would still occasionally be switched to Classic for pages where that is needed.

1

Not all pages and features of Salesforce work in Lightning. A user's environment must be able to switch back & forth between the two environments as required to open & respond to the needs of different features of the platform. The API is going to automatically switch a user as needed regardless of their preferences.

What you're doing is trying to create functionality that doesn't exist. A User's personal preferences are just that, "personal" and as an admin, you have no control over them.

0

I recently saw something on the Success Community that should generally do what you want until Salesforce provides the functionality you're looking for that's on the roadmap per @gorav answer. You can create a simple flow that runs during login which finds the user that is logging in and sets the UserPreferenceslightningExperiencePreferred to "True". No screens are shown, so the user isn't aware it's even running. The flow looks like this:

Login Flow

A detailed blog post has been written by Charles Stevenson about this which you can find at https://sfdc.click/2016/07/14/default-lex/.

2

You must log in to answer this question.

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