【发布时间】:2018-05-10 18:48:54
【问题描述】:
我正在为仪表板创建 8 个 visualforce 页面 (VFP),并且由于每个 VFP 所需数据的相似性,我希望利用单个自定义控制器(而不是 8 个控制器)。
每个 VFP 之间的唯一区别是控制器中 SOQL 语句的 WHERE 子句。我的想法是让每个 VFP 将静态(不变/硬编码)字符串传递给控制器,以便在控制器的 SOQL WHERE 子句中使用。这是我正在寻找的示例:
控制器:
public class SalesRev_UpFrontFees {
public String StageVal {get;set;}
public Integer salesVal = 0;
public Integer intTCV;
public SalesRev_UpFrontFees(){
getData();
}
public void getData() {
//Insert code to pull the hardcoded 'StageVal' from visualforce pages
String SoqlString = 'SELECT SUM(Total_Subscription_Fees__c) RevSum\n' +
'FROM Opportunity\n' +
'WHERE CloseDate >= 2018-01-01 AND CloseDate <= 2018-12-31\n' +
'AND Opportunity.RecordType.Name = \'Enterprise Opportunity\'\n' +
'AND StageName = \':StageVal\'';
AggregateResult[] groupedResults = Database.query(SoqlString);
objTCV = groupedResults[0].get('RevSum');
intTCV = Integer.valueOf(objTCV);
salesVal = (intTCV == null) ? 0 : intTCV ;
}
/*public void setStageVal(String sStageVal) {
StageVal = sStageVal;
} */
public Integer getsalesVal() {
return intTCV;
}
}
Visualforce 页面:
<apex:page controller="SalesRev_UpFrontFees">
<head>
<apex:includeScript value="{!URLFOR($Resource.VFGauge, 'VFGauge/jQuery/jquery-1.10.2.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.VFGauge, 'VFGauge/jQuery/jquery-ui-1.10.2.custom.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.Raphael, 'Raphael/resources/js/raphael.2.1.0.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.Raphael, 'Raphael/resources/js/justgage.1.0.1.js')}" />
<apex:stylesheet value="{!URLFOR($Resource.Raphael, 'Raphael/styles/style.css')}"/>
</head>
<apex:form id="myForm">
<!--- Insert way to feed the controller a string value, e.g. String StageVal = 'Closed Won'--->
<body>
<apex:pageBlock id="xxx">
<div id="gauge1" style="width:320px; height:256px"></div>
<script type="text/javascript">
var g1 = new JustGage({
id: "gauge1",
value: {!salesVal},
min: 0,
max: 1000000000,
title: "WW Sales Revenue",
levelColorsGradient: false,
gaugeWidthScale: 0.4,
valueFontSize: "5px"
});
</script>
<a id="linear-gauge" href=""></a>
</apex:pageBlock>
</body>
</apex:form>
</apex:page>
我查看了数十篇与此类似的帖子,但所有现有帖子要么 1) 处理将动态值(通常通过 JS 脚本定义)从 VFP 传递到通过按钮/selectList/等控件的控件。或者 2) 它们处理从控制器到 VFP 的传递变量;这两个都不是我需要的。我最接近解决方案的是使用此来源:https://salesforce.stackexchange.com/questions/24666/how-to-pass-javascript-value-to-controller ...但此示例需要使用 VFP 上的按钮。
不用说,我是 visualforce 的新手,但在 Python 方面有大约 4 年的编码经验(这并没有我希望的那么大)。任何如何实现这一点的示例将不胜感激!
【问题讨论】: