Schema メソッドを使用したタブの記述
Apex の記述用の API コール (describe) を実行することで、Salesforce ユーザーインターフェースで使用できるアプリケーションとそのタブに関するメタデータ情報を取得できます。また、各タブに関する詳細情報も取得できます。それぞれ describeTabs Schema メソッドと Schema.DescribeTabResult の getTabs メソッドを使用します。
この例では、各アプリケーションのタブセットを取得する方法を示します。次に、Sales アプリケーションのタブの Describe メタデータ情報を取得します。各タブのメタデータ情報には、アイコンの URL、タブがカスタムであるかどうか、色などが含まれます。タブの Describe 情報は、デバッグ出力に書き込まれます。
1// Get tab set describes for each app
2List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
3
4// Iterate through each tab set describe for each app and display the info
5for(DescribeTabSetResult tsr : tabSetDesc) {
6 String appLabel = tsr.getLabel();
7 System.debug('Label: ' + appLabel);
8 System.debug('Logo URL: ' + tsr.getLogoUrl());
9 System.debug('isSelected: ' + tsr.isSelected());
10 String ns = tsr.getNamespace();
11 if (ns == '') {
12 System.debug('The ' + appLabel + ' app has no namespace defined.');
13 }
14 else {
15 System.debug('Namespace: ' + ns);
16 }
17
18 // Display tab info for the Sales app
19 if (appLabel == 'Sales') {
20 List<Schema.DescribeTabResult> tabDesc = tsr.getTabs();
21 System.debug('-- Tab information for the Sales app --');
22 for(Schema.DescribeTabResult tr : tabDesc) {
23 System.debug('getLabel: ' + tr.getLabel());
24 System.debug('getColors: ' + tr.getColors());
25 System.debug('getIconUrl: ' + tr.getIconUrl());
26 System.debug('getIcons: ' + tr.getIcons());
27 System.debug('getMiniIconUrl: ' + tr.getMiniIconUrl());
28 System.debug('getSobjectName: ' + tr.getSobjectName());
29 System.debug('getUrl: ' + tr.getUrl());
30 System.debug('isCustom: ' + tr.isCustom());
31 }
32 }
33}
34
35// Example debug statement output
36// DEBUG|Label: Sales
37// DEBUG|Logo URL: https://MyDomainName.my.salesforce.com/img/seasonLogos/2014_winter_aloha.png
38// DEBUG|isSelected: true
39// DEBUG|The Sales app has no namespace defined.// DEBUG|-- Tab information for the Sales app --
40// (This is an example debug output for the Accounts tab.)
41// DEBUG|getLabel: Accounts
42// DEBUG|getColors: (Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme4;],
43// Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme3;],
44// Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme2;])
45// DEBUG|getIconUrl: https://MyDomainName.my.salesforce.com/img/icon/accounts32.png
46// DEBUG|getIcons: (Schema.DescribeIconResult[getContentType=image/png;getHeight=32;getTheme=theme3;
47// getUrl=https://MyDomainName.my.salesforce.com/img/icon/accounts32.png;getWidth=32;],
48// Schema.DescribeIconResult[getContentType=image/png;getHeight=16;getTheme=theme3;
49// getUrl=https://MyDomainName.my.salesforce.com/img/icon/accounts16.png;getWidth=16;])
50// DEBUG|getMiniIconUrl: https://MyDomainName.my.salesforce.com/img/icon/accounts16.png
51// DEBUG|getSobjectName: Account
52// DEBUG|getUrl: https://MyDomainName.my.salesforce.com/001/o
53// DEBUG|isCustom: false