describeSObjects()
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.
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}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.
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}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. |