An array-based version of describeSObject(); describes metadata (field list and object properties) for the specified object or array of objects. Use this call instead of describeSObject().
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 with5 // the names of the objects to describe.6 DescribeSObjectResult[] describeSObjectResults = 7 connection.describeSObjects(8 new String[] { "account", "contact", "lead" });910 // Iterate through the list of describe sObject results11 for (int i=0;i < describeSObjectResults.length; i++)12 {13 DescribeSObjectResult desObj = describeSObjectResults[i];14 // Get the name of the sObject15 String objectName = desObj.getName();16 System.out.println("sObject name: " + objectName);1718 // For each described sObject, get the fields19 Field[] fields = desObj.getFields();2021 // Get some other properties22 if (desObj.getActivateable()) System.out.println("\tActivateable");2324 // Iterate through the fields to get properties for each field25 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());3738 // Determine whether this is a picklist field39 if (field.getType() == FieldType.picklist)40 { 41 // Determine whether there are picklist values42 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 }5253 // Determine whether this is a reference field54 if (field.getType() == FieldType.reference)55 { 56 // Determine whether this field refers to another object57 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 with6 // the names of the objects to describe.7 DescribeSObjectResult[] describeSObjectResults = 8 binding.describeSObjects(9 new string[] { "account", "contact", "lead" });1011 // Iterate through the list of describe sObject results12 foreach (DescribeSObjectResult describeSObjectResult in describeSObjectResults)13 {14 // Get the name of the sObject15 String objectName = describeSObjectResult.name;16 Console.WriteLine("sObject name: " + objectName);1718 // For each described sObject, get the fields19 Field[] fields = describeSObjectResult.fields;2021 // Get some other properties22 if (describeSObjectResult.activateable) Console.WriteLine("\tActivateable");2324 // Iterate through the fields to get properties for each field25 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);3637 // Determine whether this is a picklist field38 if (field.type == fieldType.picklist)39 { 40 // Determine whether there are picklist values41 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 }5152 // Determine whether this is a reference field53 if (field.type == fieldType.reference)54 { 55 // Determine whether this field refers to another object56 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.Message72 + "\n" + e.StackTrace);73 }74}