first time working with a Lightning Web Component and Lightning Out so this may be a fairly simple question.
We're still using Salesforce Classic so I need to be able to use navigation methods which work in both Lightning and Classic. With that in mind, I've tried a few different methods to establish if the UITheme being displayed by the user is Lightning or Classic and none of them seem to work with the App and are resulting in undefined results mostly.
Scenario One (Using Salesforce new Javascript method from Summer 18):
isDesktopClassic() {
return UITheme.getUITheme() === "Theme3";
}
This results in a Promise which doesn't seem to be what was expected. Perhaps I'm incorrect on that.
Scenario Two (Using Apex)
Helper Class:
@AuraEnabled (cacheable=true)
public static boolean getIsUserInClassic(){
//Run class to see if the user is in Classic or Lightning
String themeDisplayed = UserInfo.getUiThemeDisplayed();
//Boolean for Classic
boolean displayClassic = false;
//Populate checkbox for handiness
if (themeDisplayed == 'Theme3'){
displayClassic = true;
}
return displayClassic;
}
Lightning Web Component:
import getIsUserInClassic from '@salesforce/apex/HelperClass.getIsUserInClassic';
export default class sampleClass extends NavigationMixin(LightningElement) {
@track isUserInClassic;
connectedCallback(){
getIsUserInClassic()
.then(result => {
this.isUserInClassic = result;
this.error = undefined;
}).catch(error =>{
this.error = error;
this.isUserInClassic = undefined;
})
console.log(isUserInClassic);
}
Apologies if I'm missing something fairly rudimentary and thanks for taking a look!
UITheme.getUITheme == 'Theme3'
(notice there's no parenthesis at the end), you can try that out.