function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YuuYuu 

レイアウトのメタデータを取得し、Visualforceに表示させたい

お世話になります。

Apexでページレイアウトのメタデータを取得し、
その情報を元に、Visualforce上で表示させたいと考えております。
また、上記で表示させた項目に対し、Apexで取得した値を初期値として設定したいと考えております。

ページレイアウトに項目が追加されたとき、
作成および編集画面(Visualforce)の項目を動的に表示させたい。
その際に、標準およびカスタム項目に初期値を設定したい。

下記のApexでレイアウトのメタデータを配列で取得できたのですが、表示(Visualforce)、初期値(Apex)の設定の仕方がわかりません。
下記の情報だけでは、わかりにくいとは思いますが、
何卒、ご教示をお願い致します。

・Apex
List<String> componentList = new List<String>{'Account-Account Layout'};
List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentList);
 
Best Answer chosen by Yuu
takamatakama
次のURLでメタデータから動的Visualforceバインディングを使用して画面表示を実現されている方がおられます。
https://qiita.com/s_hayashida/items/9de70cd79ba94e5095a3

また初期値については、同Visualforceに指定する拡張コントローラー(entensions)にて次のようなコードを
記載すれば、実現できます。
以下、新規レコード作成時に「Name」を設定する例です。
public AccDynEX(ApexPages.StandardController controller) {
        Account acc = (Account)controller.getRecord();
        if (acc.Id == null){
            acc.Name = '初期値';
        }
    }

 

All Answers

takamatakama
次のURLでメタデータから動的Visualforceバインディングを使用して画面表示を実現されている方がおられます。
https://qiita.com/s_hayashida/items/9de70cd79ba94e5095a3

また初期値については、同Visualforceに指定する拡張コントローラー(entensions)にて次のようなコードを
記載すれば、実現できます。
以下、新規レコード作成時に「Name」を設定する例です。
public AccDynEX(ApexPages.StandardController controller) {
        Account acc = (Account)controller.getRecord();
        if (acc.Id == null){
            acc.Name = '初期値';
        }
    }

 
This was selected as the best answer
YuuYuu
ご回答、ありがとうございます。
試してみたいと思います。