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