2011-03-30 50 views

回答

1

如果您使用的是Salesforce的API,那麼你可以使用describeSObjects()來檢索的元數據您感興趣的任何對象,包括Account對象。

的語法是:

DescribeSObjectResult [] = sfdc.describeSObjects(string sObjectType[]); 

哪裏sObjectType是高達100級的對象的陣列。

爲了描述一個帳戶,使用方法:

DescribeSObjectResult [] = sfdc.describeSObjects("account"); 

的DescribeSObjectResult陣列具有可以用於發現關於對象的信息的許多特性。例如,如果您想要屬於該帳戶對象的字段列表,則可以使用DescribeSObjectResult.Fields。

這是一些來自Salesforce API Developer's Reference的Java代碼示例。這應該有助於你開始。如果您按照開發人員參考的鏈接,也有C#示例。

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()); 
    } 
}