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);
}
this function return true ,the value of the field UserPreferencesLightningExperiencePreferred in the object user change when the user interface switch. if UserPreferencesLightningExperiencePreferred is ture => Lightning Desktop and return false, if false => Classic Desktop