Newer Version Available
Schema メソッドを使用した sObject の記述
トークンを使用する代わりに、describeSObjects Schema メソッドをコールして、記述する sObject の 1 つ以上の sObject 型の名前を渡すことで、sObject を記述することもできます。
この例では、Account 標準オブジェクトと Merchandise__c カスタムオブジェクトの 2 つの sObject 型の Describe メタデータ情報を取得します。各 sObject の Describe Result を取得したら、sObject 表示ラベル、項目数、カスタムオブジェクトであるかどうか、子リレーションの数などの返された情報をデバッグ出力に書き込みます。
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17// sObject types to describe
18String[] types = new String[]{'Account','Merchandise__c'};
19
20// Make the describe call
21Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
22
23System.debug('Got describe information for ' + results.size() + ' sObjects.');
24
25// For each returned result, get some info
26for(Schema.DescribeSobjectResult res : results) {
27 System.debug('sObject Label: ' + res.getLabel());
28 System.debug('Number of fields: ' + res.fields.getMap().size());
29 System.debug(res.isCustom() ? 'This is a custom object.' : 'This is a standard object.');
30 // Get child relationships
31 Schema.ChildRelationship[] rels = res.getChildRelationships();
32 if (rels.size() > 0) {
33 System.debug(res.getName() + ' has ' + rels.size() + ' child relationships.');
34 }
35}