Newer Version Available
describeCompactLayouts()
Syntax
1DescribeCompactLayoutsResult compactLayoutResult = connection.describeCompactLayouts(string sObjectType, ID[] recordTypeId);Usage
Use this call to retrieve information about the compact layout for a given object type. This call returns metadata about a given compact layout, including the record type mappings. For more information about compact layouts, see the Salesforce online help.
Sample Code—Java
This sample shows how to get the compact layouts of an Account sObject. It calls describeCompactLayouts() with the name of the sObject type to describe. After getting the compact layouts, the sample prints the images, fields, and action buttons found for each compact layout. Next, it prints the system default compact layout for the object, then the mapping information of record types to compact layouts.
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void testDescribeCompactLayoutsSample() {
18 try {
19 String objectToDescribe = "Account";
20 DescribeCompactLayoutsResult compactLayoutResult = connection
21 .describeCompactLayouts(objectToDescribe, null);
22 System.out.println("There are " + compactLayoutResult.getCompactLayouts().length
23 + " compact layouts for the " + objectToDescribe + " object.");
24
25 // Get all the compact layouts for the sObject
26 for (int i = 0; i < compactLayoutResult.getCompactLayouts().length; i++) {
27 DescribeCompactLayout cLayout = compactLayoutResult.getCompactLayouts()[i];
28 System.out.println(" There is a compact layout with name: " + cLayout.getName());
29 DescribeLayoutItem[] fieldItems = cLayout.getFieldItems();
30 System.out.println(" There are " + fieldItems.length + " fields in this compact layout.");
31
32 // Write field items
33 for (int j = 0; j < fieldItems.length; j++) {
34 System.out.println(j + " This compact layout has a field with name: " + fieldItems[j].getLabel());
35 }
36
37 DescribeLayoutItem[] imageItems = cLayout.getImageItems();
38 System.out.println(" There are " + imageItems.length + " image fields in this compact layout.");
39
40 // Write the image items
41 for (int j = 0; j < imageItems.length; j++) {
42 System.out.println(j + " This compact layout has an image field with name: " + imageItems[j].getLabel());
43 }
44
45 DescribeLayoutButton[] actions = cLayout.getActions();
46 System.out.println(" There are " + actions.length + " buttons in this compact layout.");
47
48 // Write the action buttons
49 for (int j = 0; j < actions.length; j++) {
50 System.out.println(j + " This compact layout has a button with name: " + actions[j].getLabel());
51 }
52
53 System.out.println("This object's default compact layout is: "
54 + compactLayoutResult.getDefaultCompactLayoutId());
55
56 RecordTypeCompactLayoutMapping[] mappings = compactLayoutResult.getRecordTypeCompactLayoutMappings();
57 System.out.println("There are " + mappings.length + " record type to compact layout mapping for the "
58 + objectToDescribe + " object.");
59 for (int j = 0; j < mappings.length; j++) {
60 System.out.println(j + " Record type " + mappings[j].getRecordTypeId()
61 + " is mapped to compact layout " + mappings[j].getCompactLayoutId());
62 }
63 }
64
65 } catch (ConnectionException ce) {
66 ce.printStackTrace();
67 }
68
69}
70Arguments
| 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. |
| recordTypeId | ID[] | Optional parameter that restricts the compact layout data returned to the specified record types. |