+ Start a Discussion
Laxman VattamLaxman Vattam 

Test Class for Lightning Mode

I'm executing apex code based on UserInfo.getUiThemeDisplayed(). If the user is in lightning mode (UserInfo.getUiThemeDisplayed() =='Theme4d'), I execute part of code and if the user is in Classic mode (UserInfo.getUiThemeDisplayed() !='Theme4d') I execute other part of code.

While writing test class, it is by default going to Classic mode part of code. To cover the lightning part of code, I have created test user with UserPreferencesLightningExperiencePreferred = true. Even with system.runas this user, user is not being considered as lightning mode and my other part of apex code is not getting covered. how to switch the user to lightning mode.

Basically system.assert(UserInfo.getUiThemeDisplayed() =='Theme4d','ERROR: Theme is not lightning...'); is failing