describeSObjects()

An array-based version of describeSObject(); describes metadata (field list and object properties) for the specified object or array of objects.

Note
Use this call instead of describeSObject().

Syntax

DescribeSObjectResult [] = 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.

public void describeSObjectsSample() 
{
  try {
    // Call describeSObjectResults and pass it an array with
    // the names of the objects to describe.
    DescribeSObjectResult[] describeSObjectResults = 
                       connection.describeSObjects(
                        new String[] { "account", "contact", "lead" });

    // Iterate through the list of describe sObject results
    for (int i=0;i < describeSObjectResults.length; i++)
    {
        DescribeSObjectResult desObj = describeSObjectResults[i];
        // Get the name of the sObject
        String objectName = desObj.getName();
        System.out.println("sObject name: " + objectName);

        // For each described sObject, get the fields
        Field[] fields = desObj.getFields();
                        
        // Get some other properties
        if (desObj.getActivateable()) System.out.println("\tActivateable");
        
        // Iterate through the fields to get properties for each field
        for(int j=0;j < fields.length; j++)
        {                        
            Field field = fields[j];
            System.out.println("\tField: " + field.getName());
            System.out.println("\t\tLabel: " + field.getLabel());
            if (field.isCustom()) 
                System.out.println("\t\tThis is a custom field.");
            System.out.println("\t\tType: " + field.getType());
            if (field.getLength() > 0)
                System.out.println("\t\tLength: " + field.getLength());
            if (field.getPrecision() > 0)
                System.out.println("\t\tPrecision: " + field.getPrecision());
            
            // Determine whether this is a picklist field
            if (field.getType() == FieldType.picklist)
            {                            
                // Determine whether there are picklist values
                PicklistEntry[] picklistValues = field.getPicklistValues();
                if (picklistValues != null && picklistValues[0] != null)
                {
                    System.out.println("\t\tPicklist values = ");
                    for (int k = 0; k < picklistValues.length; k++)
                    {
                        System.out.println("\t\t\tItem: " + picklistValues[k].getLabel());
                    }
                }
            }

            // Determine whether this is a reference field
            if (field.getType() == FieldType.reference)
            {                            
                // Determine whether this field refers to another object
                String[] referenceTos = field.getReferenceTo();
                if (referenceTos != null && referenceTos[0] != null)
                {
                    System.out.println("\t\tField references the following objects:");
                    for (int k = 0; k < referenceTos.length; k++)
                    {
                        System.out.println("\t\t\t" + referenceTos[k]);
                    }
                }
            }
        }            
    }
  } catch(ConnectionException ce) {
    ce.printStackTrace();  
  }
}

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.

public void describeSObjectsSample()
{
    try 
    {
    // Call describeSObjectResults and pass it an array with
    // the names of the objects to describe. DescribeSObjectResult[] describeSObjectResults = binding.describeSObjects( new string[] { "account", "contact", "lead" }); // Iterate through the list of describe sObject results
    foreach (DescribeSObjectResult describeSObjectResult in describeSObjectResults) { // Get the name of the sObject String objectName = describeSObjectResult.name; Console.WriteLine("sObject name: " + objectName); // For each described sObject, get the fields Field[] fields = describeSObjectResult.fields; // Get some other properties
        if (describeSObjectResult.activateable) Console.WriteLine("\tActivateable"); // Iterate through the fields to get properties for each field
        foreach (Field field in fields) { Console.WriteLine("\tField: " + field.name); Console.WriteLine("\t\tLabel: " + field.label); if (field.custom) Console.WriteLine("\t\tThis is a custom field."); Console.WriteLine("\t\tType: " + field.type); if (field.length > 0) Console.WriteLine("\t\tLength: " + field.length); if (field.precision > 0) Console.WriteLine("\t\tPrecision: " + field.precision); // Determine whether this is a picklist field
            if (field.type == fieldType.picklist) { // Determine whether there are picklist values PicklistEntry[] picklistValues = field.picklistValues; if (picklistValues != null && picklistValues[0] != null) { Console.WriteLine("\t\tPicklist values = "); for (int j = 0; j < picklistValues.Length; j++) { Console.WriteLine("\t\t\tItem: " + picklistValues[j].label); } } } // Determine whether this is a reference field
            if (field.type == fieldType.reference) { // Determine whether this field refers to another object
                string[] referenceTos = field.referenceTo; if (referenceTos != null && referenceTos[0] != null) { Console.WriteLine("\t\tField references the following objects:"); for (int j = 0; j < referenceTos.Length; j++) { Console.WriteLine("\t\t\t" + referenceTos[j]); } } } } } } catch (SoapException e) { Console.WriteLine("An unexpected error has occurred: " + e.Message + "\n" + e.StackTrace); } }

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

Faults

InvalidSObjectFault

UnexpectedErrorFault

© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.