Newer Version Available
describeLayout()
Retrieves metadata about page layouts for the specified object type.
Syntax
1DescribeLayoutResult = connection.describeLayout(string sObjectType, string layoutName, 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, see “Page Layouts” in the Salesforce online help.
Generally, user profiles have one layout associated with each object. In Enterprise, Unlimited, and Performance 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.
Layouts can be further customized in standard objects that have defined named layouts, which are separate from the primary layout for both the profile and the record type. One example of named layouts is the UserAlt layout defined on the User object, which is consumed in the Salesforce mobile app instead of the primary User layout. New layout names can only be defined by Salesforce, but customization of named layouts is controlled by administrators in the same way as primary layouts.
If you supply a null value for recordTypeIds, all the layouts for that user are returned, instead of just the layouts for each specified record type. The same layout can 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:
- To display a detail page or edit page for a record that exists, a client application first gets the recordTypeIds from the record, then it finds the layoutId associated with that recordTypeIds (through recordTypeMapping), and finally it uses that layout information to render the page.
- 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.
- A client application can access the labels for the layout, using the DescribeLayoutResult.
- describeLayout() for version 7.0 and below returns 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 doesn’t return any person account record types.
For more information about person account record types, see Person Account Record Types.
Sample Code—Java
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 third 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.
1public void describeLayoutSample(){
2 try {
3 String objectToDescribe = "Account";
4 DescribeLayoutResult dlr =
5 connection.describeLayout(objectToDescribe, null, null);
6 System.out.println("There are " + dlr.getLayouts().length +
7 " layouts for the " + objectToDescribe + " object."
8 );
9
10 // Get all the layouts for the sObject
11 for(int i = 0; i < dlr.getLayouts().length; i++) {
12 DescribeLayout layout = dlr.getLayouts()[i];
13 DescribeLayoutSection[] detailLayoutSectionList =
14 layout.getDetailLayoutSections();
15 System.out.println(" There are " +
16 detailLayoutSectionList.length +
17 " detail layout sections");
18 DescribeLayoutSection[] editLayoutSectionList =
19 layout.getEditLayoutSections();
20 System.out.println(" There are " +
21 editLayoutSectionList.length +
22 " edit layout sections");
23
24 // Write the headings of the detail layout sections
25 for(int j = 0; j < detailLayoutSectionList.length; j++) {
26 System.out.println(j +
27 " This detail layout section has a heading of " +
28 detailLayoutSectionList[j].getHeading());
29 }
30
31 // Write the headings of the edit layout sections
32 for(int x = 0; x < editLayoutSectionList.length; x++) {
33 System.out.println(x +
34 " This edit layout section has a heading of " +
35 editLayoutSectionList[x].getHeading());
36 }
37
38 // For each edit layout section, get its details.
39 for(int k = 0; k < editLayoutSectionList.length; k++) {
40 DescribeLayoutSection els =
41 editLayoutSectionList[k];
42 System.out.println("Edit layout section heading: " +
43 els.getHeading());
44 DescribeLayoutRow[] dlrList = els.getLayoutRows();
45 System.out.println("This edit layout section has " +
46 dlrList.length + " layout rows.");
47 for(int m = 0; m < dlrList.length; m++) {
48 DescribeLayoutRow lr = dlrList[m];
49 System.out.println(" This row has " +
50 lr.getNumItems() + " layout items.");
51 DescribeLayoutItem[] dliList = lr.getLayoutItems();
52 for(int n = 0; n < dliList.length; n++) {
53 DescribeLayoutItem li = dliList[n];
54 if ((li.getLayoutComponents() != null) &&
55 (li.getLayoutComponents().length > 0)) {
56 System.out.println("\tLayout item " + n +
57 ", layout component: " +
58 li.getLayoutComponents()[0].getValue());
59 }
60 else {
61 System.out.println("\tLayout item " + n +
62 ", no layout component");
63 }
64 }
65 }
66 }
67 }
68
69 // Get record type mappings
70 if (dlr.getRecordTypeMappings() != null) {
71 System.out.println("There are " +
72 dlr.getRecordTypeMappings().length +
73 " record type mappings for the " +
74 objectToDescribe + " object"
75 );
76 } else {
77 System.out.println(
78 "There are no record type mappings for the " +
79 objectToDescribe + " object."
80 );
81 }
82 } catch (ConnectionException ce) {
83 ce.printStackTrace();
84 }
85}Sample Code—C#
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 third 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.
1public void describeLayoutSample()
2{
3 try
4 {
5 String objectToDescribe = "Account";
6 DescribeLayoutResult dlr =
7 binding.describeLayout(objectToDescribe, null, null);
8 Console.WriteLine("There are " + dlr.layouts.Length +
9 " layouts for the " + objectToDescribe + " object."
10 );
11
12 // Get all the layouts for the sObject
13 for (int i = 0; i < dlr.layouts.Length; i++)
14 {
15 DescribeLayout layout = dlr.layouts[i];
16 DescribeLayoutSection[] detailLayoutSectionList =
17 layout.detailLayoutSections;
18 Console.WriteLine(" There are " +
19 detailLayoutSectionList.Length +
20 " detail layout sections");
21 DescribeLayoutSection[] editLayoutSectionList =
22 layout.editLayoutSections;
23 Console.WriteLine(" There are " +
24 editLayoutSectionList.Length +
25 " edit layout sections");
26
27 // Write the headings of the detail layout sections
28 for (int j = 0; j < detailLayoutSectionList.Length; j++)
29 {
30 Console.WriteLine(j +
31 " This detail layout section has a heading of " +
32 detailLayoutSectionList[j].heading);
33 }
34
35 // Write the headings of the edit layout sections
36 for (int x = 0; x < editLayoutSectionList.Length; x++)
37 {
38 Console.WriteLine(x +
39 " This edit layout section has a heading of " +
40 editLayoutSectionList[x].heading);
41 }
42
43 // For each edit layout, get its details.
44 for (int k = 0; k < editLayoutSectionList.Length; k++)
45 {
46 DescribeLayoutSection els =
47 editLayoutSectionList[k];
48 Console.WriteLine("Edit layout section heading: " +
49 els.heading);
50 DescribeLayoutRow[] dlrList = els.layoutRows;
51 Console.WriteLine("This edit layout section has " +
52 dlrList.Length + " layout rows.");
53 for (int m = 0; m < dlrList.Length; m++)
54 {
55 DescribeLayoutRow lr = dlrList[m];
56 Console.WriteLine(" This row has " +
57 lr.numItems + " layout items.");
58 DescribeLayoutItem[] dliList = lr.layoutItems;
59 for (int n = 0; n < dliList.Length; n++)
60 {
61 DescribeLayoutItem li = dliList[n];
62 if ((li.layoutComponents != null) &&
63 (li.layoutComponents.Length > 0))
64 {
65 Console.WriteLine("\tLayout item " + n +
66 ", layout component: " +
67 li.layoutComponents[0].value);
68 }
69 else
70 {
71 Console.WriteLine("\tLayout item " + n +
72 ", no layout component");
73 }
74 }
75 }
76 }
77
78 // Get record type mappings
79 if (dlr.recordTypeMappings != null)
80 {
81 Console.WriteLine("There are " +
82 dlr.recordTypeMappings.Length +
83 " record type mappings for the " +
84 objectToDescribe + " object");
85 }
86 else
87 {
88 Console.WriteLine(
89 "There are no record type mappings for the " +
90 objectToDescribe + " object.");
91 }
92 }
93 }
94 catch (SoapException e)
95 {
96 Console.WriteLine("An unexpected error has occurred: " +
97 e.Message + "\n" + e.StackTrace);
98 }
99}Arguments
| Name | Type | Description |
|---|---|---|
| sObjectType | string | The specified value must be a valid object for your organization. If the object is a person account, specify Account, or if it is a person contact, specify Contact. |
| layoutName | string | The specified value must be a valid named layout for this object. Layout names are obtained from namedLayoutInfos in DescribeSObjectResult. The entity name is not valid because the primary layout is not considered “named.” |
| recordTypeIds | 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 recordTypeIds regardless of the object. This value is returned in the recordTypeInfos for the master record type in the DescribeSObjectResult. A SOQL query returns a null value, not 012000000000000AAA. For information on IDs, see ID Field Type. |