オブジェクトの一覧を取得

オブジェクトの取得

getGlobalDescribe() で すべてのオブジェクト(標準とカスタム)を取得する。
DescribeSObjectResult で必要な情報を使用する。
使用しているユーザによって変化する項目もある。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for (String objectName: gd.keySet()) {
    Schema.SObjectType ot = gd.get(objectName);
    DescribeSObjectResult r = ot.getDescribe();
    System.debug(
        'label:' + r.label
        + ' name:' + r.name
        + ' prefix:' + r.keyPrefix
        + ' custom:' + r.isCustom()
        + ' customSetting:' + r.isCustomSetting()
    );
}

Last Mod: Jan 3, 2023