开发者

How to get the child nodes of a particular account in salesforce

Hi guys i want to retrieve开发者_StackOverflow社区 the child nodes of a particular account in sales force.How do i achieve this? I am not very much aware of the data model that sales force use. Any suggestions would be helpful.


If you are using the Salesforce API then you can use describeSObjects() to retrieve metadata about any object you are interested in, including the Account object.

The syntax is:

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

Where sObjectType is an array of up to 100 objects.

To describe an account, use:

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

The DescribeSObjectResult array has many properties that can be used to discover information about the object. For example, if you want a list of the fields belonging to the account object, you would use DescribeSObjectResult.Fields.

Here is some sample Java code from the Salesforce API Developer's Reference. This should help you get started. There are also C# samples if you follow the link to the developers reference.

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


I'm presuming you're using SOQL to retrive the child data. If I'm wrong please clarify.

This will depend on the relationship you're trying to access but in general you can do a query like this to select the child elements of a Parent

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

Full details of the SOQL query language are here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜