describeLayout()
指定されたオブジェクト種別のページレイアウトに関するメタデータを取得します。
構文
1DescribeLayoutResult = connection.describeLayout(string sObjectType, string layoutName, ID recordTypeID[]);使用方法
このコールを使用し、指定されたオブジェクト種別のレイアウト情報 (ユーザへのデータの表示方法) を取得します。このコールは、詳細ページレイアウト、編集ページレイアウトおよびレコードタイプの関連付けなど、指定されたページレイアウトのメタデータを返します。ページレイアウトについての詳細は、Salesforce オンラインヘルプの「ページレイアウトのカスタマイズ」を参照してください。
一般的に、ユーザプロファイルには各オブジェクトに 1 つのレイアウトが関連付けられています。Enterprise Edition、Unlimited Edition、および Performance Edition では、ユーザプロファイルはオブジェクトごとに複数のレイアウトを使用でき、各レイアウトは指定されたレコードタイプに固有です。このコールは、適用される場合複数のレイアウトのメタデータを返します。
定義された名前付きレイアウトがある標準オブジェクトではレイアウトをさらにカスタマイズできます。名前付きレイアウトは、プロファイルとレコードタイプの両方で主レイアウトとは分離されています。名前付きレイアウトの例として、User オブジェクトで定義される UserAlt レイアウトが挙げられます。これは、主 User レイアウトではなく、Salesforce1 で使用されます。新規レイアウト名は、Salesforce でのみ定義できますが、名前付きレイアウトのカスタマイズは主レイアウトと同様にシステム管理者によって制御されます。
recordTypeIds に null 値を指定した場合、指定されたレコードタイプに対するレイアウトだけではなく、そのユーザのすべてのレイアウトが返されます。同じレイアウトが、ユーザプロファイルの複数のレコードタイプに割り当てられていることもあるため、その場合は 1 つのレイアウトのみが返されます。
レイアウトを記述する手順は次のとおりです。
- 既存のレコードの詳細ページまたは���集ページを表示するには、クライアントアプリケーションはまずレコードの recordTypeIds を取得し、recordTypeMapping を使用してその recordTypeIds に関連付けられた layoutId を見つけます。そのレイアウト情報を使用し、最終的にページを表示します。
- 編集ページの作成バージョンを表示するには、クライアントアプリケーションは最初に 1 つ以上のレコードタイプが利用可能かどうかを確認します。利用可能な場合、ユーザに選択肢を表示します。レコードタイプを選択すると、クライアントアプリケーションはレイアウト情報を使用しページを表示します。また、RecordTypeMapping の選択リストの値を使用し、選択リスト項目で使用する有効な選択リスト値を表示します。
- クライアントアプリケーションは DescribeLayoutResult を使用してレイアウトのラベルにアクセスできるようになります。
- バージョン 7.0 以前の describeLayout() は、タブのデフォルトが個人取引先レコードタイプである場合も、デフォルトのレコードタイプ��して法人取引先レコードタイプを返します。バージョン 8.0 以降では、デフォルトのレコードタイプは常にタブのデフォルトとなります。
- バージョン 7.0 以前では、describeLayout() は個人取引先レコードタイプは一切返しません。
個人取引先レコードタイプについての詳細は、「個人取引先のレコードタイプ」を参照してください。
サンプルコード —Java
このサンプルでは、取引先 sObject のレイアウトを取得する方法を示します。記述する sObject 種別の名前を使用して、describeLayout() をコールします。このサンプルでは、3 番目の引数としてレコードタイプ ID を指定しません。つまり、指定された sObject に対して組織でレコードタイプが定義されている場合は、すべてのレコードタイプのレイアウトが返されます。レイアウトの取得後に、このサンプルでは、見つかった詳細セクションと編集セクションの数とそのヘッダーを書き込みます。次に、編集レイアウトセクションごとに反復処理を行い、そのコンポーネントを取得します。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeLayoutSample(){
18 try {
19 String objectToDescribe = "Account";
20 DescribeLayoutResult dlr =
21 connection.describeLayout(objectToDescribe, null, null);
22 System.out.println("There are " + dlr.getLayouts().length +
23 " layouts for the " + objectToDescribe + " object."
24 );
25
26 // Get all the layouts for the sObject
27 for(int i = 0; i < dlr.getLayouts().length; i++) {
28 DescribeLayout layout = dlr.getLayouts()[i];
29 DescribeLayoutSection[] detailLayoutSectionList =
30 layout.getDetailLayoutSections();
31 System.out.println(" There are " +
32 detailLayoutSectionList.length +
33 " detail layout sections");
34 DescribeLayoutSection[] editLayoutSectionList =
35 layout.getEditLayoutSections();
36 System.out.println(" There are " +
37 editLayoutSectionList.length +
38 " edit layout sections");
39
40 // Write the headings of the detail layout sections
41 for(int j = 0; j < detailLayoutSectionList.length; j++) {
42 System.out.println(j +
43 " This detail layout section has a heading of " +
44 detailLayoutSectionList[j].getHeading());
45 }
46
47 // Write the headings of the edit layout sections
48 for(int x = 0; x < editLayoutSectionList.length; x++) {
49 System.out.println(x +
50 " This edit layout section has a heading of " +
51 editLayoutSectionList[x].getHeading());
52 }
53
54 // For each edit layout section, get its details.
55 for(int k = 0; k < editLayoutSectionList.length; k++) {
56 DescribeLayoutSection els =
57 editLayoutSectionList[k];
58 System.out.println("Edit layout section heading: " +
59 els.getHeading());
60 DescribeLayoutRow[] dlrList = els.getLayoutRows();
61 System.out.println("This edit layout section has " +
62 dlrList.length + " layout rows.");
63 for(int m = 0; m < dlrList.length; m++) {
64 DescribeLayoutRow lr = dlrList[m];
65 System.out.println(" This row has " +
66 lr.getNumItems() + " layout items.");
67 DescribeLayoutItem[] dliList = lr.getLayoutItems();
68 for(int n = 0; n < dliList.length; n++) {
69 DescribeLayoutItem li = dliList[n];
70 if ((li.getLayoutComponents() != null) &&
71 (li.getLayoutComponents().length > 0)) {
72 System.out.println("\tLayout item " + n +
73 ", layout component: " +
74 li.getLayoutComponents()[0].getValue());
75 }
76 else {
77 System.out.println("\tLayout item " + n +
78 ", no layout component");
79 }
80 }
81 }
82 }
83 }
84
85 // Get record type mappings
86 if (dlr.getRecordTypeMappings() != null) {
87 System.out.println("There are " +
88 dlr.getRecordTypeMappings().length +
89 " record type mappings for the " +
90 objectToDescribe + " object"
91 );
92 } else {
93 System.out.println(
94 "There are no record type mappings for the " +
95 objectToDescribe + " object."
96 );
97 }
98 } catch (ConnectionException ce) {
99 ce.printStackTrace();
100 }
101}サンプルコード —C#
このサンプルでは、取引先 sObject のレイアウトを取得する方法を示します。記述する sObject 種別の名前を使用して、describeLayout() をコールします。このサンプルでは、3 番目の引数としてレコードタイプ ID を指定しません。つまり、指定された sObject に対して組織でレコードタイプが定義されている場合は、すべてのレコードタイプのレイアウトが返されます。レイアウトの取得後に、このサンプルでは、見つかった詳細セクションと編集セクションの数とそのヘッダーを書き込みます。次に、編集レイアウトセクションごとに反復処理を行い、そのコンポーネントを取得します。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void describeLayoutSample()
18{
19 try
20 {
21 String objectToDescribe = "Account";
22 DescribeLayoutResult dlr =
23 binding.describeLayout(objectToDescribe, null, null);
24 Console.WriteLine("There are " + dlr.layouts.Length +
25 " layouts for the " + objectToDescribe + " object."
26 );
27
28 // Get all the layouts for the sObject
29 for (int i = 0; i < dlr.layouts.Length; i++)
30 {
31 DescribeLayout layout = dlr.layouts[i];
32 DescribeLayoutSection[] detailLayoutSectionList =
33 layout.detailLayoutSections;
34 Console.WriteLine(" There are " +
35 detailLayoutSectionList.Length +
36 " detail layout sections");
37 DescribeLayoutSection[] editLayoutSectionList =
38 layout.editLayoutSections;
39 Console.WriteLine(" There are " +
40 editLayoutSectionList.Length +
41 " edit layout sections");
42
43 // Write the headings of the detail layout sections
44 for (int j = 0; j < detailLayoutSectionList.Length; j++)
45 {
46 Console.WriteLine(j +
47 " This detail layout section has a heading of " +
48 detailLayoutSectionList[j].heading);
49 }
50
51 // Write the headings of the edit layout sections
52 for (int x = 0; x < editLayoutSectionList.Length; x++)
53 {
54 Console.WriteLine(x +
55 " This edit layout section has a heading of " +
56 editLayoutSectionList[x].heading);
57 }
58
59 // For each edit layout, get its details.
60 for (int k = 0; k < editLayoutSectionList.Length; k++)
61 {
62 DescribeLayoutSection els =
63 editLayoutSectionList[k];
64 Console.WriteLine("Edit layout section heading: " +
65 els.heading);
66 DescribeLayoutRow[] dlrList = els.layoutRows;
67 Console.WriteLine("This edit layout section has " +
68 dlrList.Length + " layout rows.");
69 for (int m = 0; m < dlrList.Length; m++)
70 {
71 DescribeLayoutRow lr = dlrList[m];
72 Console.WriteLine(" This row has " +
73 lr.numItems + " layout items.");
74 DescribeLayoutItem[] dliList = lr.layoutItems;
75 for (int n = 0; n < dliList.Length; n++)
76 {
77 DescribeLayoutItem li = dliList[n];
78 if ((li.layoutComponents != null) &&
79 (li.layoutComponents.Length > 0))
80 {
81 Console.WriteLine("\tLayout item " + n +
82 ", layout component: " +
83 li.layoutComponents[0].value);
84 }
85 else
86 {
87 Console.WriteLine("\tLayout item " + n +
88 ", no layout component");
89 }
90 }
91 }
92 }
93
94 // Get record type mappings
95 if (dlr.recordTypeMappings != null)
96 {
97 Console.WriteLine("There are " +
98 dlr.recordTypeMappings.Length +
99 " record type mappings for the " +
100 objectToDescribe + " object");
101 }
102 else
103 {
104 Console.WriteLine(
105 "There are no record type mappings for the " +
106 objectToDescribe + " object.");
107 }
108 }
109 }
110 catch (SoapException e)
111 {
112 Console.WriteLine("An unexpected error has occurred: " +
113 e.Message + "\n" + e.StackTrace);
114 }
115}引数
| 名前 | 型 | 説明 |
|---|---|---|
| sObjectType | string | 指定された値は、組織で有効なオブジェクトである必要があります。オブジェクトが個人取引先である場合は Account を指定し、個人取引先責任者である場合は Contact を指定します。 |
| layoutName | string | 指定された値は、このオブジェクトの有効な名前付きレイアウトである必要があります。レイアウト名は、DescribeSObjectResult の namedLayoutInfos から取得されます。主レイアウトは「名前付き」とは見なされないため、エンティティ名は有効ではありません。 |
| recordTypeIds | ID[] |
任意で指定できるパラメータにより指定されたレコードタイプに返されたレイアウトデータを制限します。 主レコードタイプのレイアウトを取得するには、オブジェクトに関わらず recordTypeIds に値 012000000000000AAA を指定します。この値は、DescribeSObjectResult で主レコードタイプの recordTypeInfos として返されます。SOQL クエリでは、012000000000000AAA ではなく null 値を返します。 ID についての詳細は、「ID データ型」を参照してください。 |