In this post we will see how we can Switch to Lightning Experience Using Apex salesforce. When we are logged in salesforce org, then we can switch to lightning experience using UI. But what if we want to switch other users to lightning experience, so there are two ways.
- Individually login as all user and click on Switch to Lightning Experience : (That’s NOT a good Solution).
- Update all users from apex code. (That’s a Good Solution).
So what needs to be done for second option. First see the “UserPreferencesLightningExperiencePreferred” field on User Object. Then we need to set this field to true using code. See the code snippet below, you can execute this code from developer console.
Apex Code
1 2 3 4 5 6 7 8 |
// Fetching Users, you can specify where clause if any List<User> usersToSwitchToLightning = [SELECT id, UserPreferencesLightningExperiencePreferred FROM User]; // Updating UserPreferencesLightningExperiencePreferred field to true for(User u : usersToSwitchToLightning){ u.UserPreferencesLightningExperiencePreferred = true; } // DML to update users UPDATE usersToSwitchToLightning; |
Use this if you need to mass update users to switch to lightning experience.
Nice 🙂