describeLayout()

Retrieves metadata about page layouts for the specified object type.

Syntax

DescribeLayoutResult = sfdc.describeLayout(string sObjectType, ID recordTypeID[]);

Usage

Use this call to retrieve information about the layout (presentation of data to users) for a given object type. This call returns metadata about a given page layout, such as the detail page layout, the edit page layout, and the record type mappings. For additional information about page layouts, see "Customizing Page Layouts" in the Salesforce online help.

Generally, user profiles have one layout associated with each object. In Enterprise and Unlimited Editions, user profiles can have multiple layouts per object, where each layout is specific to a given record type. This call returns metadata for multiple layouts, if applicable.

If you supply a null value for recordTypeId, all the layouts for that user are returned, instead of just the layouts for each specified record type. The same layout may be associated with multiple record types for the user’s profile, in which case there would only be one layout returned.

Note
This call is an advanced API call that is typically used only by partners who have written custom page rendering code for generating output on a specialized device (for example, on PDAs) and need to examine the layout details of an object before rendering the page output.

Use the following procedure to describe layouts:

  1. To display a detail page or edit page for a record that already exists, a client application first gets the recordTypeId from the record, then it finds the layoutId associated with that recordTypeId (through recordTypeMapping), and finally it uses that layout information to render the page.
  2. To display the create version of an edit page, a client application first determines whether more than one record type is available and, if so, presents the user with a choice. Once a record type has been chosen, then the client application uses the layout information to render the page. It uses the picklist values from the RecordTypeMapping to display valid picklist values for picklist fields.
  3. A client application can access the labels for the layout, using the DescribeLayoutResult.
The following restrictions apply to person account record types:
  • describeLayout() for version 7.0 and below will return the default business account record type as the default record type even if the tab default is a person account record type. In version 8.0 and after, it will always be the tab default.
  • describeLayout() for version 7.0 and below will not return any person account record types.

For more information about person account record types, see Person Account Record Types.

Sample Code—Java

private void describeLayoutSample(){
  try {
    String objectToDescribe = getUserInput("Enter an object name: ");
    DescribeLayoutResult dlr = binding.describeLayout(objectToDescribe);
    System.out.println("There are " + dlr.getLayouts().length +
        " layouts for the " + objectToDescribe + " object.");
    for (int i=0;i<dlr.getLayouts().length;i++){
      DescribeLayout layout = dlr.getLayouts(i);
      System.out.println(" There are " +
          layout.getDetailLayoutSections().length + " detail layout sections");
      for (int j=0;j<layout.getDetailLayoutSections().length;j++){
        DescribeLayoutSection dls = layout.getDetailLayoutSections(j);
        System.out.println(new Integer(j).toString() +
            " This section has a heading of " + dls.getHeading());
        if (layout.getEditLayoutSections() != null) {
          System.out.println("There are " +
              layout.getEditLayoutSections().length + " edit layout sections");
        }
        for (int k=0;k<layout.getEditLayoutSections().length;k++){
          DescribeLayoutSection els = layout.getEditLayoutSections(k);
          System.out.println(new Integer(k).toString() +
              " This section has a heading of " + els.getHeading());
          System.out.println("This section has " +
             els.getLayoutRows().length + " layout rows.");
          for (int l=0;l<els.getLayoutRows().length;l++){
            DescribeLayoutRow lr = els.getLayoutRows(l);
            System.out.println(" This row has " + lr.getNumItems() + " items.");
            for (int h=0;h<lr.getLayoutItems().length;h++){
              DescribeLayoutItem li = lr.getLayoutItems(h);
              if (li.getLayoutComponents() != null) {
                System.out.println(" " +
                    new Integer(h).toString() +
                   " " + li.getLayoutComponents(0).getValue());
              }
            }
          }
        }
      }
    }
    if (dlr.getRecordTypeMappings() != null)
      System.out.println("There are " +
          dlr.getRecordTypeMappings().length + " record type mappings for the " +
          objectToDescribe + " object");
    else
      System.out.println("There are no record type mappings for the " +
          objectToDescribe + " object.");
  } catch (Exception e) {
    System.out.println("An exceptions was caught: " + e.getMessage());
   getUserInput("Press enter to continue...");
  }
}

Sample Code—C#

private void describeLayoutSample() 
{
   try 
   {
      Console.Write("Enter the name of an object to describe the layout of: ");
      string objectToDescribe = Console.ReadLine();
      sforce.DescribeLayoutResult dlr = binding.describeLayout(objectToDescribe);
      Console.WriteLine("There are " + dlr.layouts.Length + " layouts for the " + 
         objectToDescribe + " object.");
      for (int i=0;i<dlr.layouts.Length;i++)
      {
         sforce.DescribeLayout layout = dlr.layouts[i];
         Console.WriteLine("    There are " + layout.detailLayoutSections.Length +
         " detail layout sections");
         for (int j=0;j<layout.detailLayoutSections.Length;j++)
         {
            sforce.DescribeLayoutSection dls = layout.detailLayoutSections[j];
            Console.WriteLine(j + "        This section has a heading of " +
         dls.heading);
         }
         if (layout.editLayoutSections != null) 
         {
            Console.WriteLine("    There are " + layout.editLayoutSections.Length
            + " edit layout sections");
            for (int j=0;j<layout.editLayoutSections.Length;j++)
            {
               sforce.DescribeLayoutSection els = layout.editLayoutSections[j];
               Console.WriteLine(j + "        This section has a heading of " +
               els.heading);
               Console.WriteLine("This section has " + els.layoutRows.Length + 
               " layout rows.");
               for (int k=0;k<els.layoutRows.Length;k++)
               {
                  sforce.DescribeLayoutRow lr = els.layoutRows[k];
                  Console.WriteLine("            This row has " + lr.numItems + 
                  " items.");
                  for (int h=0;h<lr.layoutItems.Length;h++)
                  {
                     sforce.DescribeLayoutItem li = lr.layoutItems[h];
                    if (li.layoutComponents != null) 
                        Console.WriteLine("               " + h + " " + 
                          li.layoutComponents[0].value);
                  }
               }
            }
         }
      }
      if (dlr.recordTypeMappings != null) 
         Console.WriteLine("There are " + dlr.recordTypeMappings.Length + 
         " record type mappings for the " + objectToDescribe + " object");
      else
         Console.WriteLine("There are no record type mappings for the " +
         objectToDescribe + " object.");
   } 
   catch (Exception e) 
   {
      Console.WriteLine("An exceptions was caught: " + e.Message);
   }
}

Arguments

Name Type Description
sObjectType string The specified value must be a valid object for your organization. For a complete list of objects, see Standard Objects. If the object is a person account, specify Account, or if it is a person contact, specify Contact.
recordTypeId ID[]

Optional parameter restricts the layout data returned to the specified record types.

To retrieve the layout for the master record type, specify the value 012000000000000AAA for the recordTypeId regardless of the object. This value is returned in the recordTypeInfos for the master record type in the DescribeSObjectResult. Note that a SOQL query returns a null value, not 012000000000000AAA.

For information on IDs, see ID Field Type.

Response

DescribeLayoutResult

Faults

InvalidSObjectFault

UnexpectedErrorFault

See Also:
API Call Basics
https://wiki.apexdevnet.com/index.php/Sample_SOAP_Messages
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.