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

private void describeSObjectsSample()
{
  try {
    DescribeSObjectResult[] describeSObjectResults =
      binding.describeSObjects(new String[] {"account", "contact", "lead"});
    for (int x=0;x<describeSObjectResults.length;x++)
    {
      DescribeSObjectResult describeSObjectResult = describeSObjectResults[x];
      // Retrieve fields from the results
      Field[] fields = describeSObjectResult.getFields();
      // Get the name of the object
      String objectName = describeSObjectResult.getName();
      // Get some flags
      boolean isActivateable = describeSObjectResult.isActivateable();
      System.out.println("Object name: " + objectName);
      // Many other values are accessible
      if (fields != null)
      {
        // Iterate through the fields to get properties for each field
        for (int i = 0; i < fields.length; i++)
        {
          Field field = fields[i];
          int byteLength = field.getByteLength();
          int digits = field.getDigits();
          String label = field.getLabel();
          int length = field.getLength();
          String name = field.getName();
          PicklistEntry[] picklistValues = field.getPicklistValues();
          int precision = field.getPrecision();
          String[] referenceTos = field.getReferenceTo();
          int scale = field.getScale();
          FieldType fieldType = field.getType();
          boolean fieldIsCreateable = field.isCreateable();
          System.out.println("Field name: " + name);
          // Determine whether there are picklist values
          if (picklistValues != null && picklistValues[0] != null)
          {
            System.out.println("Picklist values = ");
            for (int j = 0; j < picklistValues.length; j++)
            {
              if (picklistValues[j].getLabel() != null)
              {
                System.out.println(" Item: " +
                    picklistValues[j].getLabel());
              }
            }
          }
          // Determine whether this field refers to another object
          if (referenceTos != null && referenceTos[0] != null)
          {
            System.out.println("Field references the following objects:");
            for (int j = 0; j < referenceTos.length; j++)
            {
              System.out.println(" " + referenceTos[j]);
            }
          }
        }
      }
    }
  } catch (Exception ex) {
    System.out.println("\nFailed to get object descriptions, error message was: \n" + 
                       ex.getMessage());
  }
}

Sample Code—C#

private void describeSObjectsSample() 
{
    sforce.DescribeSObjectResult[] describeSObjectResults = 
                       binding.describeSObjects(new string[] {"account", "contact", "lead"});
    for (int x=0;x<describeSObjectResults.Length;x++) 
    {
        sforce.DescribeSObjectResult describeSObjectResult = 
                           describeSObjectResults[x];
        // Retrieve fields from the results
        sforce.Field[] fields = describeSObjectResult.fields;
        // Get the name of the object
        String objectName = describeSObjectResult.name;
        // Get some flags
        bool isActivateable = describeSObjectResult.activateable;
        // Many other values are accessible
        if (fields != null) 
        {
            // Iterate through the fields to get properties for each field
            for (int i = 0; i < fields.Length; i++) 
            {
                sforce.Field field = fields[i];
                int byteLength = field.byteLength;
                int digits = field.digits;
                string label = field.label;
                int length = field.length;
                string name = field.name;
                sforce.PicklistEntry[] picklistValues = field.picklistValues;
                int precision = field.precision;
                string[] referenceTos = field.referenceTo;
                int scale = field.scale;
                sforce.fieldType fieldType = field.type;
                bool fieldIsCreateable = field.createable;
                // Determine whether there are picklist values
                if (picklistValues != null && picklistValues[0] != null) 
                {
                    Console.WriteLine("Picklist values = ");
                    for (int j = 0; j < picklistValues.Length; j++) 
                    {
                        if (picklistValues[j].label != null) 
                        {
                            Console.WriteLine(" Item: " + picklistValues[j].label);
                        }
                    }
                }
                // Determine whether this field refers to another object
                if (referenceTos != null && referenceTos[0] != null) 
                {
                    Console.WriteLine("Field references the following objects:");
                    for (int j = 0; j < referenceTos.Length; j++) 
                    {
                        Console.WriteLine(" " + referenceTos[j]);
                   }
               }
            }
        }
    }
}

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

See Also:
describeSObject()
describeGlobal()
API Call Basics
Using the Partner WSDL
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.