Retrieves metadata about page layouts for the specified object type.
DescribeLayoutResult = connection.describeLayout(string sObjectType, ID recordTypeID[]);
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.
Use the following procedure to describe layouts:
For more information about person account record types, see Person Account Record Types.
This sample shows how to get the layouts of an Account sObject. It calls describeLayout() with the name of the sObject type to describe. It doesn’t specify record type IDs as a second argument, which means that layouts for all record types will be returned if record types are defined in your org for the specified sObject. After getting the layout, the sample writes the number of detail and edit sections found and their headings. Next, it iterates through each edit layout section and retrieves its components.
public void describeLayoutSample(){ try { String objectToDescribe = "Account"; DescribeLayoutResult dlr = connection.describeLayout(objectToDescribe, null); System.out.println("There are " + dlr.getLayouts().length + " layouts for the " + objectToDescribe + " object." ); // Get all the layouts for the sObject for(int i = 0; i < dlr.getLayouts().length; i++) { DescribeLayout layout = dlr.getLayouts()[i]; DescribeLayoutSection[] detailLayoutSectionList = layout.getDetailLayoutSections(); System.out.println(" There are " + detailLayoutSectionList.length + " detail layout sections"); DescribeLayoutSection[] editLayoutSectionList = layout.getEditLayoutSections(); System.out.println(" There are " + editLayoutSectionList.length + " edit layout sections"); // Write the headings of the detail layout sections for(int j = 0; j < detailLayoutSectionList.length; j++) { System.out.println(j + " This detail layout section has a heading of " + detailLayoutSectionList[j].getHeading()); } // Write the headings of the edit layout sections for(int x = 0; x < editLayoutSectionList.length; x++) { System.out.println(x + " This edit layout section has a heading of " + editLayoutSectionList[x].getHeading()); } // For each edit layout section, get its details. for(int k = 0; k < editLayoutSectionList.length; k++) { DescribeLayoutSection els = editLayoutSectionList[k]; System.out.println("Edit layout section heading: " + els.getHeading()); DescribeLayoutRow[] dlrList = els.getLayoutRows(); System.out.println("This edit layout section has " + dlrList.length + " layout rows."); for(int m = 0; m < dlrList.length; m++) { DescribeLayoutRow lr = dlrList[m]; System.out.println(" This row has " + lr.getNumItems() + " layout items."); DescribeLayoutItem[] dliList = lr.getLayoutItems(); for(int n = 0; n < dliList.length; n++) { DescribeLayoutItem li = dliList[n]; if ((li.getLayoutComponents() != null) && (li.getLayoutComponents().length > 0)) { System.out.println("\tLayout item " + n + ", layout component: " + li.getLayoutComponents()[0].getValue()); } else { System.out.println("\tLayout item " + n + ", no layout component"); } } } } } // Get record type mappings 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 (ConnectionException ce) { ce.printStackTrace(); } }
This sample shows how to get the layouts of an Account sObject. It calls describeLayout() with the name of the sObject type to describe. It doesn’t specify record type IDs as a second argument, which means that layouts for all record types will be returned if record types are defined in your org for the specified sObject. After getting the layout, the sample writes the number of detail and edit sections found and their headings. Next, it iterates through each edit layout section and retrieves its components.
public void describeLayoutSample() { try { String objectToDescribe = "Account"; DescribeLayoutResult dlr = binding.describeLayout(objectToDescribe, null); Console.WriteLine("There are " + dlr.layouts.Length + " layouts for the " + objectToDescribe + " object." ); // Get all the layouts for the sObject
for (int i = 0; i < dlr.layouts.Length; i++) { DescribeLayout layout = dlr.layouts[i]; DescribeLayoutSection[] detailLayoutSectionList = layout.detailLayoutSections; Console.WriteLine(" There are " + detailLayoutSectionList.Length + " detail layout sections"); DescribeLayoutSection[] editLayoutSectionList = layout.editLayoutSections; Console.WriteLine(" There are " + editLayoutSectionList.Length + " edit layout sections"); // Write the headings of the detail layout sections
for (int j = 0; j < detailLayoutSectionList.Length; j++) { Console.WriteLine(j + " This detail layout section has a heading of " + detailLayoutSectionList[j].heading); } // Write the headings of the edit layout sections
for (int x = 0; x < editLayoutSectionList.Length; x++) { Console.WriteLine(x + " This edit layout section has a heading of " + editLayoutSectionList[x].heading); } // For each edit layout, get its details.
for (int k = 0; k < editLayoutSectionList.Length; k++) { DescribeLayoutSection els = editLayoutSectionList[k]; Console.WriteLine("Edit layout section heading: " + els.heading); DescribeLayoutRow[] dlrList = els.layoutRows; Console.WriteLine("This edit layout section has " + dlrList.Length + " layout rows."); for (int m = 0; m < dlrList.Length; m++) { DescribeLayoutRow lr = dlrList[m]; Console.WriteLine(" This row has " + lr.numItems + " layout items."); DescribeLayoutItem[] dliList = lr.layoutItems; for (int n = 0; n < dliList.Length; n++) { DescribeLayoutItem li = dliList[n]; if ((li.layoutComponents != null) && (li.layoutComponents.Length > 0)) { Console.WriteLine("\tLayout item " + n + ", layout component: " + li.layoutComponents[0].value); } else { Console.WriteLine("\tLayout item " + n + ", no layout component"); } } } } // Get record type mappings
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 (SoapException e) { Console.WriteLine("An unexpected error has occurred: " + e.Message + "\n" + e.StackTrace); } }
| 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. |