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?