describeSObject()
指定されたオブジェクトのメタデータ (項目リストとオブジェクトプロパティ) を表します。
構文
1DescribeSObjectResult = connection.describeSObject(string sObjectType);使用方法
指定されたオブジェクトのメタデータを取得するには、describeSObject() を使用します。最初に describeGlobal() をコールして組織のすべてのオブジェクトのリストを取得します。その後リスト内を反復処理し、describeSObject() を使用して個々のオブジェクトのメタデータを取得します。
組織のデータのメタデータを取得するには、クライアントアプリケーションは条件を満たすアクセス権限でログインする必要があります。詳細は、「データアクセスに影響する要素」を参照してください。
サンプルコード —Java
このサンプルでは、describeSObject() をコールし、取引先 sObject に describe を実行します。sObject 名、表示ラベル、項目などの、sObject の describe result の一部のプロパティを取得します。次に、項目を反復処理し、項目のプロパティを取得します。選択リスト項目では、選択リスト値を取得して、参照項目では参照されているオブジェクト名を取得します。このサンプルでは、取得した sObject および項目のプロパティをコンソールに書き込みます。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeSObjectSample() {
18 try {
19 // Make the describe call
20 DescribeSObjectResult describeSObjectResult =
21 connection.describeSObject("Account");
22
23 // Get sObject metadata
24 if (describeSObjectResult != null) {
25 System.out.println("sObject name: " +
26 describeSObjectResult.getName());
27 if (describeSObjectResult.isCreateable())
28 System.out.println("Createable");
29
30 // Get the fields
31 Field[] fields = describeSObjectResult.getFields();
32 System.out.println("Has " + fields.length + " fields");
33
34 // Iterate through each field and gets its properties
35 for (int i = 0; i < fields.length; i++) {
36 Field field = fields[i];
37 System.out.println("Field name: " + field.getName());
38 System.out.println("Field label: " + field.getLabel());
39
40 // If this is a picklist field, show the picklist values
41 if (field.getType().equals(FieldType.picklist)) {
42 PicklistEntry[] picklistValues =
43 field.getPicklistValues();
44 if (picklistValues != null) {
45 System.out.println("Picklist values: ");
46 for (int j = 0; j < picklistValues.length; j++) {
47 if (picklistValues[j].getLabel() != null) {
48 System.out.println("\tItem: " +
49 picklistValues[j].getLabel()
50 );
51 }
52 }
53 }
54 }
55
56 // If a reference field, show what it references
57 if (field.getType().equals(FieldType.reference)) {
58 System.out.println("Field references the " +
59 "following objects:");
60 String[] referenceTos = field.getReferenceTo();
61 for (int j = 0; j < referenceTos.length; j++) {
62 System.out.println("\t" + referenceTos[j]);
63 }
64 }
65 }
66 }
67 } catch (ConnectionException ce) {
68 ce.printStackTrace();
69 }
70}サンプルコード —C#
このサンプルでは、describeSObject() をコールし、取引先 sObject に describe を実行します。sObject 名、表示ラベル、項目などの、sObject の describe result の一部のプロパティを取得します。次に、項目を反復処理し、項目のプロパティを取得します。選択リスト項目では、選択リスト値を取得して、参照項目では参照されているオブジェクト名を取得します。このサンプルでは、取得した sObject および項目のプロパティをコンソールに書き込みます。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeSObjectSample() {
18 try {
19 // Make the describe call
20 DescribeSObjectResult describeSObjectResult =
21 binding.describeSObject("Account");
22
23 // Get sObject metadata
24 if (describeSObjectResult != null) {
25 Console.WriteLine("sObject name: " +
26 describeSObjectResult.name);
27 if (describeSObjectResult.createable)
28 Console.WriteLine("Createable");
29
30 // Get the fields
31 Field[] fields = describeSObjectResult.fields;
32 Console.WriteLine("Has " + fields.Length + " fields");
33
34 // Iterate through each field and gets its properties
35 for (int i = 0; i < fields.Length; i++) {
36 Field field = fields[i];
37 Console.WriteLine("Field name: " + field.name);
38 Console.WriteLine("Field label: " + field.label);
39
40 // If this is a picklist field, show the picklist values
41 if (field.type.Equals(fieldType.picklist)) {
42 PicklistEntry[] picklistValues =
43 field.picklistValues;
44 if (picklistValues != null) {
45 Console.WriteLine("Picklist values: ");
46 for (int j = 0; j < picklistValues.Length; j++) {
47 if (picklistValues[j].label != null) {
48 Console.WriteLine("\tItem: " +
49 picklistValues[j].label);
50 }
51 }
52 }
53 }
54
55 // If a reference field, show what it references
56 if (field.type.Equals(fieldType.reference)) {
57 Console.WriteLine("Field references the " +
58 "following objects:");
59 String[] referenceTos = field.referenceTo;
60 for (int j = 0; j < referenceTos.Length; j++) {
61 Console.WriteLine("\t" + referenceTos[j]);
62 }
63 }
64 }
65 }
66 } catch (SoapException e) {
67 Console.WriteLine("An unexpected error has occurred: " +
68 e.Message + "\n" + e.StackTrace);
69 }
70}引数
| 名前 | 型 | 説明 |
|---|---|---|
| sObjectType | string | オブジェクト。指定された値は、組織で有効なオブジェクトである必要があります。完全なオブジェクトのセットについては、「標準オブジェクト」を参照してください。 |