IUserFilterProvider2の実装の具体例として、取引先責任者の選択レコードによって所属する取引先のすべての商談を表示する方法を説明します。
最初にRaySheetが提供するApexインターフェースを使用してApexクラスを作成する。ここでは、Apexクラスにパラメーターとしてわたってきた「取引先責任者」のIDから所属する「取引先」のIDを取得しgcss.UserFilterに設定します。
「Apex クラス」ページで「新規」ボタンをクリックし、「Apex Class」に次のコードを貼り付ける。
global class ContactOpportunityRelatedAccount implements gcss.IUserFilterProvider2 {
global gcss.UserFilter getUserFilter(string objectName, Map<String,Object> context){
if (objectName != 'Opportunity'){
return null;
}
if(context.isEmpty()){
return null;
}
String contactID = context.get('ContactID').toString();
List<Contact> contactList = [SELECT Id, AccountId FROM Contact WHERE Id = :contactID Limit 1];
Contact contact = contactList.get(0);
gcss.UserFilter result = new gcss.UserFilter();
if(String.isEmpty(contact.AccountId)){
result.whereClause = 'Id = :userArg1';
}else{
result.whereClause = 'AccountId = :userArg1';
}
result.userArg1 = contact.AccountId;
return result;
}
}
「保存」をクリックする。
Visualforceページを作成します。「取引先責任者」と「取引先」の2つの「どこでもView(gcss:Spreadsheetコンポーネント)」を配置します。さらに、「取引先責任者」の選択レコード変更イベントで1.で作成したApexクラスを用いてカスタムフィルルターが設定されるようにします。
<apex:page sidebar="false" standardStylesheets="true" showHeader="true" docType="html-5.0" title="Contact Opportunnity Sample Page">
<apex:slds />
<style type="text/css">
.gcss-object-pane{
display: none;
}
.gcss-folder-panel{
display: none;
}
.gcss .gcss-titlebar .gcss-titlebar__object-btn{
display: none;
}
.gcss-titlebar__logo{
display: none;
}
.gcss .gcss-toolbar__PaneGroup{
display: none;
}
.gcss .gcss-design-panel__related-tab{
display:none;
}
.gcss .gcss-titlebar_help-popup .gcss-help-popup .gcss-help-popup__config-link {
display:none;
}
.gcss-button-action{
width:80px;
}
</style>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(){
setTimeout(function(){
init();
});
}, false);
document.addEventListener("load", function(){
setTimeout(function(){
init();
});
}, false);
function init(){
if (window.isRaySheetSampleInitialized){
return;
}
window.isRaySheetSampleInitialized = true;
window.needCleanCustomerFilter = false;
let contactSheet = gcbg.getRaySheet("contactSheet");
let opportunitySheet = gcbg.getRaySheet("opportunitySheet");
contactSheet.onSelectedRecordChanged(function (id) {
if(window.selectedContactId == id){
return;
}
window.selectedContactId = id;
var filterContext = {};
filterContext["ContactID"] = id;
opportunitySheet.setUserFilterProvider("ContactOpportunityRelatedAccount");
opportunitySheet.setUserFilterProviderContext(filterContext);
});
}
</script>
<div class="slds-grid slds-grid_vertical">
<div class="slds-col slds-p-around_xx-small" style="height:400px">
<gcss:Spreadsheet id="contactSheet" FolderId="a0C0o00000tLaA5EAK" ViewId="a060o00001YEMIDAA5" allowEdit="true" allowAdd="true" allowDelete="true" allowPaste="true"
allowDragFill="true" allowDragAndDrop="true" allowPinRecords="true" allowObjectActions="true"
allowFreezeColumn="true" allowFormatColumn="true" allowUISort="true" allowUIFilter="true"
allowResize="true" showTitleBar="false" showToolbar="true" allowRefresh="true" allowFind="true"
allowExport="true" allowReadingPane="false" alwaysShowGridline="true" showFormulaBar="false"
allowDetailTip="true" allowMassAddNote="true" allowMassAddTask="true" allowWorkingColumn="false"
allowFormulaColumn="true" allowManageView="true" allowDesignView="true" allowEditFavorite="false"
allowSummaryRow="true" allowQueryPanel="false" allowRestrictPicklistByRecordType="true" ></gcss:Spreadsheet>
</div>
<div class="slds-col slds-p-around_xx-small" style="height:400px;">
<gcss:Spreadsheet id="opportunitySheet" FolderId="a0C0o00000tLaA9EAK" ViewId="a060o00001YEMIXAA5" allowEdit="true" allowAdd="true" allowDelete="true" allowPaste="true"
allowDragFill="true" allowDragAndDrop="true" allowPinRecords="true" allowObjectActions="true"
allowFreezeColumn="true" allowFormatColumn="true" allowUISort="true" allowUIFilter="true"
allowResize="true" showTitleBar="false" showToolbar="true" allowRefresh="true" allowFind="true"
allowExport="true" allowReadingPane="false" alwaysShowGridline="true" showFormulaBar="false"
allowDetailTip="true" allowMassAddNote="true" allowMassAddTask="true" allowWorkingColumn="false"
allowFormulaColumn="true" allowManageView="true" allowDesignView="true" allowEditFavorite="false"
allowSummaryRow="true" allowQueryPanel="false" allowRestrictPicklistByRecordType="true" ></gcss:Spreadsheet>
</div>
</div>
</apex:page>
“FolderId”属性と”ViewId”属性の値の設定方法についてはどこでもViewの基本を参照してください。
このVisualforceページはフォルダーモードが前提です。オブジェクトモードの場合は、gcss:Spreadsheetコンポーネントの属性”FolderId”の部分を”object”に変更してください。
Visualforceページは、既定ではシステム管理者のプロファイルを割り当てられたユーザーだけが表示できます。システム管理者以外のプロファイルにも許可するには、Visualforceページのセキュリティを設定します。
作成したVisualforceページのタブを作成して動作を確認します。