Newer Version Available
describeLayout()
Retrieves metadata about page layouts for the specified object type.
Syntax
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.
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.
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. |