sforce logo

describeSObject


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

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 this 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() { 
 
   // 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().intValue(); 
            int digits = field.getDigits().intValue(); 
            String label = field.getLabel(); 
            int length = field.getLength().intValue(); 
            String name = field.getName(); 
            PicklistEntry[] picklistValues = field.getPicklistValues(); 
            int precision = field.getPrecision().intValue(); 
            String[] referenceTos = field.getReferenceTo(); 
            int scale = field.getScale().intValue(); 
            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]); 
               } 
            } 
         } 
      } 
   } 
} 

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 sforce objects, see List of sforce Objects.

Response

DescribeSObjectResult

Fault

InvalidSObjectFault

UnexpectedErrorFault

See Also

describeGlobal

Sample SOAP Messages-describeSObject

Concepts

sforce Partner Web Services API


© Copyright 2000-2003 SalesForce.com, Inc.
All rights reserved • Various trademarks held by their respective owners.