この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

describeLayout()

指定されたオブジェクト種別のページレイアウトに関するメタデータを取得します。

構文

1DescribeLayoutResult = connection.describeLayout(string sObjectType, string layoutName, ID recordTypeID[]);

使用方法

このコールを使用し、指定されたオブジェクト種別のレイアウト情報 (ユーザへのデータの表示方法) を取得します。このコールは、詳細ページレイアウト、編集ページレイアウトおよびレコードタイプの関連付けなど、指定されたページレイアウトのメタデータを返します。詳細は、Salesforce オンラインヘルプの「ページレイアウト」を参照してください。

一般的に、ユーザプロファイルには各オブジェクトに 1 つのレイアウトが関連付けられています。Enterprise Edition、Unlimited Edition、および Performance Edition では、ユーザプロファイルはオブジェクトごとに複数のレイアウトを使用でき、各レイアウトは指定されたレコードタイプに固有です。このコールは、適用される場合複数のレイアウトのメタデータを返します。

定義された名前付きレイアウトがある標準オブジェクトではレイアウトをさらにカスタマイズできます。名前付きレイアウトは、プロファイルとレコードタイプの両方で主レイアウトとは分離されています。名前付きレイアウトの例として、User オブジェクトで定義される UserAlt レイアウトが挙げられます。これは、主 User レイアウトではなく、Salesforce モバイルアプリケーションで使用されます。新規レイアウト名は、Salesforce でのみ定義できますが、名前付きレイアウトのカスタマイズは主レイアウトと同様にシステム管理者によって制御されます。

recordTypeIds に null 値を指定した場合、指定されたレコードタイプに対するレイアウトだけではなく、そのユーザのすべてのレイアウトが返されます。同じレイアウ��が、ユーザプロファイルの複数のレコードタイプに割り当てられていることもあるため、その場合は 1 つのレイアウトのみが返されます。

このコールは複雑な API コールであり、通常は、特殊な端末 (PDA など) のために、カスタムページ表示コードを記述したパートナーが使用します。また、ページの出力結果を表示する前に、レイアウトの詳細を確認する必要があります。

メモ

レイアウトを記述する手順は次のとおりです。

  1. 既存のレコードの詳細ページまたは編集ページを表示するには、クライアントアプリケーションはまずレコードの recordTypeIds を取得し、recordTypeMapping を使用してその recordTypeIds に関連付けられた layoutId を見つけます。そのレイアウト情報を使用し、最終的にページを表示します。
  2. 編集ページの作成バージョンを表示するには、クライアントアプリケーションは最初に 1 つ以上のレコードタイプが利用可能かどうかを確認します。利用可能な場合、ユーザに選択肢を表示します。レコードタイプを選択すると、クライアントアプリケーションはレイアウト情報を使用しページを表示します。また、RecordTypeMapping の選択リストの値を使用し、選択リスト項目で使用する有効な選択リスト値を表示します。
  3. クライアントアプリケーションは DescribeLayoutResult を使用してレイアウトのラベルにアクセスできるようになります。
個人取引先レコードタイプでは次の制限が適用されます。
  • バージョン 7.0 以前の describeLayout() は、タブのデフォルトが個人取引先レコードタイプである場合も、デフォルトのレコードタイプとして法人取引先レコードタイプを返します。バージョン 8.0 以降では、デフォルトのレコードタイプは常にタブのデフォルトとなります。
  • バージョン 7.0 以前では、describeLayout() は個人取引先レコードタイプは一切返しません。

個人取引先レコードタイプについての詳細は、「個人取引先のレコードタイプ」を参照してください。

サンプルコード —Java

このサンプルでは、取引先 sObject のレイアウトを取得する方法を示します。記述する sObject 種別の名前を使用して、describeLayout() をコールします。このサンプルでは、3 番目の引数としてレコードタイプ ID を指定しません。つまり、指定された sObject に対して組織でレコードタイプが定義されている場合は、すべてのレコードタイプのレイアウトが返されます。レイアウトの取得後に、このサンプルでは、見つかった詳細セクションと編集セクションの数とそのヘッダーを書き込みます。次に、編集レイアウトセクションごとに反復処理を行い、そのコンポーネントを取得します。

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}

サンプルコード —C#

このサンプルでは、取引先 sObject のレイアウトを取得する方法を示します。記述する sObject 種別の名前を使用して、describeLayout() をコールします。このサンプルでは、3 番目の引数としてレコードタイプ ID を指定しません。つまり、指定された sObject に対して組織でレコードタイプが定義されている場合は、すべてのレコードタイプのレイアウトが返されます。レイアウトの取得後に、このサンプルでは、見つかった詳細セクションと編集セクションの数とそのヘッダーを書き込みます。次に、編集レイアウトセクションごとに反復処理を行い、そのコンポーネントを取得します。

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}

引数

名前 説明
sObjectType string 指定された値は、組織で有効なオブジェクトである必要があります。オブジェクトが個人取引先である場合は Account を指定し、個人取引先責任者である場合は Contact を指定します。
layoutName string 指定された値は、このオブジェクトの有効な名前付きレイアウトである必要があります。レイアウト名は、DescribeSObjectResult の namedLayoutInfos から取得されます。主レイアウトは「名前付き」とは見なされないため、エンティティ名は有効ではありません。
recordTypeIds ID[]

任意で指定できるパラメータにより指定されたレコードタイプに返されたレイアウトデータを制限します。

主レコードタイプのレイアウトを取得するには、オブジェクトに関わらず recordTypeIds に値 012000000000000AAA を指定します。この値は、DescribeSObjectResult で主レコードタイプの recordTypeInfos として返されます。SOQL クエリでは、012000000000000AAA ではなく null 値を返します。

ID についての詳細は、「ID データ型」を参照してください。