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