7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apex で組織の設定情報取得方法について

Last updated at Posted at 2019-05-27

#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;}
}
7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?