1
0

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 1 year has passed since last update.

【Salesforce】【Apex】オブジェクト・項目の取得

Posted at

自分用の備忘録(*'ω'*)

オブジェクトのAPI名でSObjectTypeを取得

Schema.SObjectType sObjectType = Schema.getGlobalDescribe().get('hogehoge');

SObjectTypeのインスタンスでSObjectFieldを取得

Map<String, Schema.SObjectField> sObjectFieldMap = sObjectType.getDescribe().fields.getMap();

任意のオブジェクトの任意のデータ型の項目API名を取得

取引先の電話型項目を取得する例

// オブジェクトの取得
Schema.SObjectType sObjectType = Schema.getGlobalDescribe().get('Account');
        
// 項目の取得
Map<String, Schema.SObjectField> sObjectFieldMap = sObjectType.getDescribe().fields.getMap();

// 電話型の項目の取得
List<String> phoneFieldList = new List<String>();
for (Schema.SObjectField field : sObjectFieldMap.values()) {
    if(field.getDescribe().getType() == Schema.DisplayType.Phone){
        phoneFieldList.add(field.getDescribe().getName());
    }
}

DisplayType 列挙でデータ型を指定します

参考

SObjectType

SObjectField

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?