describeSObject()

Describes metadata (field list and object properties) for the specified object.

Note
describeSObjects() supersedes this call. Use describeSObjects() instead of this call.

Syntax

DescribeSObjectResult = sfdc.describeSObject(string sObjectType);

Usage

Use describeSObject() to obtain metadata for a given object. You can first call describeGlobal() to retrieve a list of all objects for your organization, then iterate through the list and use describeSObject() to obtain metadata about individual objects.

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.

Sample Code—Java

public void describeSample()
{
  try {
    // Invoke describeSObject and save results in DescribeSObjectResult
    DescribeSObjectResult describeSObjectResult = binding.describeSObject("Account");
    // Determine whether the describeSObject call succeeded.
    if (! (describeSObjectResult == null)) {
      // 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();
      // 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();
          // Determine whether there are picklist values
          if (picklistValues != 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) {
            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 Account description, error message was: \n" + 
                       ex.getMessage());
  }
  getUserInput("Press enter to continue...");
}

Sample Code—C#

private void sObjectDescribe()
{
   //Invoke describeSObject and save results in DescribeSObjectResult
   DescribeSObjectResult dsr = binding.describeSObject("Account");

   //Get value that indicates whether we can create a record
   bool canCreate = dsr.createable;

   //Get a field and save its name
   String fldName = dsr.fields[0].name;
}

Arguments

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:
describeSObjects()
describeGlobal()
API Call Basics
Using the Partner WSDL
https://wiki.apexdevnet.com/index.php/Sample_SOAP_Messages
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.