如何获取salesforce中特定帐户的子节点

时间:2011-03-30 14:43:22

标签: salesforce

大家好我想要检索销售人员中特定帐户的子节点。我如何实现这一目标? 我不太了解销售人员使用的数据模型。任何的意见都将会有帮助。

2 个答案:

答案 0 :(得分: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());
  }
}

答案 1 :(得分:0)

我假设您正在使用SOQL来检索子数据。如果我错了请澄清。

这取决于您尝试访问的关系,但通常您可以执行此类查询以选择父级的子元素

SELECT id,name,(SELECT id,FirstName,LastName,Email FROM Contacts)FROM Account其中Name ='Acme'

SOQL查询语言的完整详细信息如下:http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm