通过 Apex 和 Visualforce(Salesforce 网络)过滤报告
Filtering reports through Apex and Visualforce (Salesforce web)
我正在尝试打印出 Salesforce 自定义对象数据库并使用过滤器。筛选器工作正常,但 "All" 筛选器不显示完整的 table 作为默认值,或者当我从另一个筛选器单击 "All" 时。我怎样才能做到这一点?
这里是相关的 Apex 代码:
public string itemPickValue{get; set;}
public List<QC_Issue__c> issuesList{get; set;}
public List<QC_Issue__c> results;
public List<QC_Issue__c> getIssues() {
results = Database.query(
'SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c Order By Component_Category__c, Issue_Name__c'
);
return results;
}
public void getIssuesList() {
if(itemPickValue.equals('All')) issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c');
issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c WHERE Component_Category__c =: itemPickValue');
}
这里是相关的 Visualforce 代码:
<apex:pageBlock title="QC Glossary" id="qc_issues_list">
<h3>Filter by Component Category:</h3>
<br></br>
<!-->Start Filter and List<-->
<apex:selectList size="1" value="{!itemPickValue}">
<apex:actionSupport event="onchange" action="{!getIssuesList}" rerender="table"/>
<apex:selectOption itemLabel="All" itemValue="All"></apex:selectOption>
<apex:selectOption itemLabel="Animation/VFX" itemValue="Animation/VFX"></apex:selectOption>
</apex:selectList>
<br></br>
<br></br>
<apex:pageBlockTable id="table" value="{!issuesList}" var="qc" columnsWidth="10%, 5%, 50%, 10%, 10%, 10%, 10%">
<apex:column value="{!qc.Component_Category__c }"/>
<apex:column value="{!qc.Issue_Name__c }"/>
<apex:column value="{!qc.Issue_Description__c}"/>
<apex:column value="{!qc.Severity_1_Criteria__c}"/>
<apex:column value="{!qc.Severity_2_Criteria__c}"/>
<apex:column value="{!qc.Severity_3_Criteria__c}"/>
<apex:column value="{!qc.File__c}"/>
</apex:pageBlockTable>
我做了以下更改
- 删除了代码重复,使用 getIssues 方法而不是复制 SOQL 语句。
- 添加了一个if/else子句;您的主要问题是在
getIssuesList
中,您有一个 if 语句,如果 true 会将完整结果存储在 issuesList
中,然后立即在下一行中用尝试使用类别名称的过滤列表覆盖它 'All'
这里还有很多其他事情要指出;但我暂时不说了。
结果:
public String itemPickValue{get; set;}
public List<QC_Issue__c> issuesList{get; set;}
public List<QC_Issue__c> results;
public List<QC_Issue__c> getIssues() {
results = Database.query(
'SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c Order By Component_Category__c, Issue_Name__c'
);
return results;
}
public void getIssuesList() {
if(itemPickValue.equals('All')) {
issuesList = getIssues();
} else {
issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c WHERE Component_Category__c =: itemPickValue');
}
}
我正在尝试打印出 Salesforce 自定义对象数据库并使用过滤器。筛选器工作正常,但 "All" 筛选器不显示完整的 table 作为默认值,或者当我从另一个筛选器单击 "All" 时。我怎样才能做到这一点?
这里是相关的 Apex 代码:
public string itemPickValue{get; set;}
public List<QC_Issue__c> issuesList{get; set;}
public List<QC_Issue__c> results;
public List<QC_Issue__c> getIssues() {
results = Database.query(
'SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c Order By Component_Category__c, Issue_Name__c'
);
return results;
}
public void getIssuesList() {
if(itemPickValue.equals('All')) issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c');
issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c WHERE Component_Category__c =: itemPickValue');
}
这里是相关的 Visualforce 代码:
<apex:pageBlock title="QC Glossary" id="qc_issues_list">
<h3>Filter by Component Category:</h3>
<br></br>
<!-->Start Filter and List<-->
<apex:selectList size="1" value="{!itemPickValue}">
<apex:actionSupport event="onchange" action="{!getIssuesList}" rerender="table"/>
<apex:selectOption itemLabel="All" itemValue="All"></apex:selectOption>
<apex:selectOption itemLabel="Animation/VFX" itemValue="Animation/VFX"></apex:selectOption>
</apex:selectList>
<br></br>
<br></br>
<apex:pageBlockTable id="table" value="{!issuesList}" var="qc" columnsWidth="10%, 5%, 50%, 10%, 10%, 10%, 10%">
<apex:column value="{!qc.Component_Category__c }"/>
<apex:column value="{!qc.Issue_Name__c }"/>
<apex:column value="{!qc.Issue_Description__c}"/>
<apex:column value="{!qc.Severity_1_Criteria__c}"/>
<apex:column value="{!qc.Severity_2_Criteria__c}"/>
<apex:column value="{!qc.Severity_3_Criteria__c}"/>
<apex:column value="{!qc.File__c}"/>
</apex:pageBlockTable>
我做了以下更改
- 删除了代码重复,使用 getIssues 方法而不是复制 SOQL 语句。
- 添加了一个if/else子句;您的主要问题是在
getIssuesList
中,您有一个 if 语句,如果 true 会将完整结果存储在issuesList
中,然后立即在下一行中用尝试使用类别名称的过滤列表覆盖它 'All'
这里还有很多其他事情要指出;但我暂时不说了。
结果:
public String itemPickValue{get; set;}
public List<QC_Issue__c> issuesList{get; set;}
public List<QC_Issue__c> results;
public List<QC_Issue__c> getIssues() {
results = Database.query(
'SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c Order By Component_Category__c, Issue_Name__c'
);
return results;
}
public void getIssuesList() {
if(itemPickValue.equals('All')) {
issuesList = getIssues();
} else {
issuesList = Database.query('SELECT Component_Category__c, Issue_Name__c, Issue_Description__c, Severity_1_Criteria__c, Severity_2_Criteria__c, Severity_3_Criteria__c, File__c FROM QC_Issue__c WHERE Component_Category__c =: itemPickValue');
}
}