Newer Version Available
describeSObjects()
An array-based version of describeSObject(); describes metadata (field list and object properties) for the specified object or array of objects.
Syntax
1DescribeSObjectResult [] = connection.describeSObjects(string sObjectType[] );Usage
Use describeSObjects() to obtain metadata for a given object or array of objects. You can first call describeGlobal() to retrieve a list of all objects for your organization, then iterate through the list and use describeSObjects() to obtain metadata about individual objects. The describeSObjects() call is limited to a maximum of 100 objects returned.
Your client application must be logged in with sufficient access rights to retrieve metadata about your organization’s data. For more information, see Factors that Affect Data Access.
In organizations where person accounts are enabled, this call shows Accounts as not createable if the profile does not have access to any business account record types.
Sample Code—Java
This sample calls describeSObjects() to perform describes on account, contact, and lead. It iterates through the sObject describe results, gets the properties and fields for each sObject in the result, and writes them to the console. For picklist fields, it writes the picklist values. For reference fields, it writes the referenced object names.
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}Sample Code—C#
This sample calls describeSObjects() to perform describes on account, contact, and lead. It iterates through the sObject describe results, gets the properties and fields for each sObject in the result, and writes them to the console. For picklist fields, it writes the picklist values. For reference fields, it writes the referenced object names.
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}Arguments
The describeSObjects() call takes in an array of sObjects.
| Name | Type | Description |
|---|---|---|
| sObjectType | string | Object. The specified value must be a valid object for your organization. For a complete list of objects, see Standard Objects. |
Response
DescribeSObjectResult