参考URL
https://qiita.com/hrk623/items/b6d76f866fb8d9140e2c
利用する場面:
一つのレポートへ遷移するボタンは、
コミュニティ側とSalesforce側両方利用してます。
遷移のURLは違うから、実行環境の判断は必要となります。
取得できる情報
- 実行環境
- コミュニティ
- Lightning Experience
- Salesforce モバイルアプリ
- Lightning Experience ビルダー
- コミュニティビルダー
- コミュニティプレビュー
- 実行ユーザ
- ゲストユーザ
- 外部ユーザ
- 内部ユーザ
public class LightningContextController {
public class Error {
@AuraEnabled public String message;
@AuraEnabled public Boolean hasError = true;
public Error(String message){
this.message = message;
}
}
@AuraEnabled
public static Object getContext() {
try {
Map<String, Object> ctx = new Map<String, Object>();
ctx.put('isSite', String.isNotBlank(Site.getSiteId()));
ctx.put('uiThemeDisplayed', UserInfo.getUiThemeDisplayed());
ctx.put('isInternalUser', Auth.CommunitiesUtil.isInternalUser());
ctx.put('isGuestUser', Auth.CommunitiesUtil.isGuestUser());
return ctx;
} catch (Exception e) {
return new Error(e.getMessage());
}
}
}