describeSObjects()
describeSObject() の配列をベースとするバージョン。指定されたオブジェクトまたはオブジェクトの配列のメタデータ (項目リストとオブジェクトプロパティ) を取得します。
構文
1DescribeSObjectResult [] = connection.describeSObjects(string sObjectType[] );使用方法
指定されたオブジェクトまたはオブジェクト配列のメタデータを取得するには describeSObjects() を使用します。最初に describeGlobal() をコールして組織のすべてのオブジェクトのリストを取得します。その後リスト内を反復処理し、describeSObjects() を使用して個々のオブジェクトのメタデータを取得します。describeSObjects() コールが返すことができるオブジェクトの最大数は 100 個です。
組織のデータのメタデータを取得するには、クライアントアプリケーションは条件を満たすアクセス権限でログインする必要があります。詳細は、「データアクセスに影響する要素」を参照してください。
個人取引先が有効な組織では、法人取引先を示すレコードタイプへのアクセス権がプロファイルに割り当てられない限り、このコールでは Account が作成不可能として表されます。
サンプルコード —Java
このサンプルでは、describeSObjects() をコールし、取引先、取引先責任者、およびリードの describe を実行します。返された sObject のリストを反復処理し、各 sObject のプロパティおよび項目を取得して、コンソールにそれらを書き込みます。選択リスト項目では、選択リスト値を書き込みます。参照項目では、参照されているオブジェクト名を書き込みます。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeSObjectsSample()
18{
19 try {
20 // Call describeSObjectResults and pass it an array with
21 // the names of the objects to describe.
22 DescribeSObjectResult[] describeSObjectResults =
23 connection.describeSObjects(
24 new String[] { "account", "contact", "lead" });
25
26 // Iterate through the list of describe sObject results
27 for (int i=0;i < describeSObjectResults.length; i++)
28 {
29 DescribeSObjectResult desObj = describeSObjectResults[i];
30 // Get the name of the sObject
31 String objectName = desObj.getName();
32 System.out.println("sObject name: " + objectName);
33
34 // For each described sObject, get the fields
35 Field[] fields = desObj.getFields();
36
37 // Get some other properties
38 if (desObj.getActivateable()) System.out.println("\tActivateable");
39
40 // Iterate through the fields to get properties for each field
41 for(int j=0;j < fields.length; j++)
42 {
43 Field field = fields[j];
44 System.out.println("\tField: " + field.getName());
45 System.out.println("\t\tLabel: " + field.getLabel());
46 if (field.isCustom())
47 System.out.println("\t\tThis is a custom field.");
48 System.out.println("\t\tType: " + field.getType());
49 if (field.getLength() > 0)
50 System.out.println("\t\tLength: " + field.getLength());
51 if (field.getPrecision() > 0)
52 System.out.println("\t\tPrecision: " + field.getPrecision());
53
54 // Determine whether this is a picklist field
55 if (field.getType() == FieldType.picklist)
56 {
57 // Determine whether there are picklist values
58 PicklistEntry[] picklistValues = field.getPicklistValues();
59 if (picklistValues != null && picklistValues[0] != null)
60 {
61 System.out.println("\t\tPicklist values = ");
62 for (int k = 0; k < picklistValues.length; k++)
63 {
64 System.out.println("\t\t\tItem: " + picklistValues[k].getLabel());
65 }
66 }
67 }
68
69 // Determine whether this is a reference field
70 if (field.getType() == FieldType.reference)
71 {
72 // Determine whether this field refers to another object
73 String[] referenceTos = field.getReferenceTo();
74 if (referenceTos != null && referenceTos[0] != null)
75 {
76 System.out.println("\t\tField references the following objects:");
77 for (int k = 0; k < referenceTos.length; k++)
78 {
79 System.out.println("\t\t\t" + referenceTos[k]);
80 }
81 }
82 }
83 }
84 }
85 } catch(ConnectionException ce) {
86 ce.printStackTrace();
87 }
88}サンプルコード —C#
このサンプルでは、describeSObjects() をコールし、取引先、取引先責任者、およびリードの describe を実行します。返された sObject のリストを反復処理し、各 sObject のプロパティおよび項目を取得して、コンソールにそれらを書き込みます。選択リスト項目では、選択リスト値を書き込みます。参照項目では、参照されているオブジェクト名を書き込みます。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeSObjectsSample()
18{
19 try
20 {
21 // Call describeSObjectResults and pass it an array with
22 // the names of the objects to describe.
23 DescribeSObjectResult[] describeSObjectResults =
24 binding.describeSObjects(
25 new string[] { "account", "contact", "lead" });
26
27 // Iterate through the list of describe sObject results
28 foreach (DescribeSObjectResult describeSObjectResult in describeSObjectResults)
29 {
30 // Get the name of the sObject
31 String objectName = describeSObjectResult.name;
32 Console.WriteLine("sObject name: " + objectName);
33
34 // For each described sObject, get the fields
35 Field[] fields = describeSObjectResult.fields;
36
37 // Get some other properties
38 if (describeSObjectResult.activateable) Console.WriteLine("\tActivateable");
39
40 // Iterate through the fields to get properties for each field
41 foreach (Field field in fields)
42 {
43 Console.WriteLine("\tField: " + field.name);
44 Console.WriteLine("\t\tLabel: " + field.label);
45 if (field.custom)
46 Console.WriteLine("\t\tThis is a custom field.");
47 Console.WriteLine("\t\tType: " + field.type);
48 if (field.length > 0)
49 Console.WriteLine("\t\tLength: " + field.length);
50 if (field.precision > 0)
51 Console.WriteLine("\t\tPrecision: " + field.precision);
52
53 // Determine whether this is a picklist field
54 if (field.type == fieldType.picklist)
55 {
56 // Determine whether there are picklist values
57 PicklistEntry[] picklistValues = field.picklistValues;
58 if (picklistValues != null && picklistValues[0] != null)
59 {
60 Console.WriteLine("\t\tPicklist values = ");
61 for (int j = 0; j < picklistValues.Length; j++)
62 {
63 Console.WriteLine("\t\t\tItem: " + picklistValues[j].label);
64 }
65 }
66 }
67
68 // Determine whether this is a reference field
69 if (field.type == fieldType.reference)
70 {
71 // Determine whether this field refers to another object
72 string[] referenceTos = field.referenceTo;
73 if (referenceTos != null && referenceTos[0] != null)
74 {
75 Console.WriteLine("\t\tField references the following objects:");
76 for (int j = 0; j < referenceTos.Length; j++)
77 {
78 Console.WriteLine("\t\t\t" + referenceTos[j]);
79 }
80 }
81 }
82 }
83 }
84 }
85 catch (SoapException e)
86 {
87 Console.WriteLine("An unexpected error has occurred: " + e.Message
88 + "\n" + e.StackTrace);
89 }
90}引数
describeSObjects() コールは sObject の任意の配列を取ることができます。
| 名前 | 型 | 説明 |
|---|---|---|
| sObjectType | string | オブジェクト。指定された値は、組織で有効なオブジェクトである必要があります。完全なオブジェクトのセットについては、「標準オブジェクト」を参照してください。 |