#1.組織の設定情報取得方法
下記の四つ方法を使って組織の設定情報を取得する。
#2.実装例(OrganizationMetadata)
public class OrganizationMetadata {
private static OrganizationMetadata instance;
private OrganizationMetadata (){}
public static OrganizationMetadata getInstance() {
if (instance == null) {
instance = new OrganizationMetadata();
// Organization オブジェクト
Organization orgInfo = [SELECT Id, Name, InstanceName, NamespacePrefix, OrganizationType, IsSandbox FROM Organization LIMIT 1];
instance.InstanceName = orgInfo.InstanceName;
instance.IsProduction = orgInfo.IsSandbox == false;
instance.IsSandbox = orgInfo.IsSandbox;
instance.Namespace = orgInfo.NamespacePrefix;
instance.OrganizationId = orgInfo.Id;
instance.OrganizationName = orgInfo.Name;
instance.OrganizationType = orgInfo.OrganizationType;
// Organization クラス
ConnectApi.OrganizationSettings orgSetting = ConnectApi.Organization.getSettings();
instance.isCommunityEnabled = orgSetting.features.communitiesEnabled;
instance.IsChatterEnabled = orgSetting.features.chatter;
instance.IsMultiCurrencyEnabled = orgSetting.features.multiCurrency;
// Schema クラス
Map<String, Schema.SobjectType> sobjectTypes = Schema.getGlobalDescribe();
instance.IsPersonAccountEnabled = sobjectTypes.get('Account').getDescribe().fields.getMap().containsKey('IsPersonAccount');
instance.IsTerritoryManagementEnabled = sobjectTypes.containsKey('Territory');
// Url
instance.BaseUrl = Url.getSalesforceBaseUrl().toExternalForm();
}
return instance;
}
public String InstanceName {get; private set;}
public Boolean IsProduction {get; private set;}
public Boolean IsSandbox {get; private set;}
public String Namespace {get; private set;}
public Id OrganizationId {get; private set;}
public String OrganizationName {get; private set;}
public String OrganizationType {get; private set;}
public Boolean isCommunityEnabled {get; private set;}
public Boolean IsChatterEnabled {get; private set;}
public Boolean IsMultiCurrencyEnabled {get; private set;}
public Boolean IsPersonAccountEnabled {get; private set;}
public Boolean IsTerritoryManagementEnabled {get; private set;}
public String BaseUrl {get; private set;}
}