describeSObject()

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

Note
describeSObjects() supersedes describeSObject(). Use describeSObjects() instead of describeSObject().

Syntax

DescribeSObjectResult = connection.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 describeSObject() {
  try {
    DescribeSObjectResult describeSObjectResult = 
        connection.describeSObject("Account");
    if (describeSObjectResult != null) {
      Field[] fields = describeSObjectResult.getFields();
      String objectName = describeSObjectResult.getName();
      boolean isActivateable =
          describeSObjectResult.isActivateable();
      if (fields != null) {
        for (int i = 0; i < fields.length; i++) {
          Field field = fields[i];
          String name = field.getName();
          String label = field.getLabel();
          PicklistEntry[] picklistValues = 
              field.getPicklistValues();
          if (picklistValues != null) {
            System.out.println("Picklist values: ");
            for (int j = 0; j < picklistValues.length; j++) {
              if (picklistValues[j].getLabel() != null) {
                System.out.println("\tItem: " + 
                    picklistValues[j].getLabel()
                );
              }
            }
          }
          String[] referenceTos = field.getReferenceTo();
          if (referenceTos != null) {
            System.out.println("Field references the" +
                "following objects:"
            );
            for (int j = 0; j < referenceTos.length; j++) {
              System.out.println("\t" + referenceTos[j]);
            }
          }
        }
      }
    }
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}

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

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