在Salesforce.com上,您可以按RecordType过滤apex:pageBlockTable吗?

时间:2013-10-31 20:57:04

标签: salesforce visualforce apex

我有以下visualforce页面,需要通过case.recortype或case.recordtype.id字段过滤相关列表或pageblocktables。任何人都可以指导我找到如何做到这一点?感谢

<apex:page standardController="Account" >
 <apex:pageblock title="Cases" >
     <apex:pageblockSection >
     <apex:relatedList title="Support Cases" list="Cases"/>
     </apex:pageblockSection>
     <apex:pageblockSection >
     <apex:relatedList title="Training Cases" list="Cases"/>
     </apex:pageblockSection>
 </apex:pageblock>
 <apex:pageBlock title="Support Cases" >
     <apex:pageBlockTable value="{!Account.Cases}" var="c">
      <apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
      <apex:column value="{!c.Contact.Name}"/>
      <apex:column value="{!c.Subject}"/>
      <apex:column value="{!c.Priority}"/> 
      <apex:column value="{!c.CreatedDate}"/> 
      <apex:column value="{!c.status}"/>      
      <apex:column value="{!c.createdbyId}"/>
 </apex:pageBlockTable> 
 </apex:pageBlock>
  <apex:pageBlock title="Training Cases" >
     <apex:pageBlockTable value="{!Account.Cases}" var="c">
      <apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
      <apex:column value="{!c.Contact.Name}"/>
      <apex:column value="{!c.Subject}"/>
      <apex:column value="{!c.Priority}"/> 
      <apex:column value="{!c.CreatedDate}"/> 
      <apex:column value="{!c.status}"/>      
      <apex:column value="{!c.createdbyId}"/>
 </apex:pageBlockTable> 
 </apex:pageBlock>

</apex:page>

更新:这是我实际上最终做的事情:

页:

<apex:page standardController="account" extensions="SupportCasefilter,TrainingCasefilter">
 <apex:form >
     <apex:pageBlock title="Support Cases">    
             <apex:pageBlockTable value="{!SupportCases}" var="s">
                  <apex:column headervalue="Case"><apex:outputLink value="/{!s.id}">{!s.CaseNumber}</apex:outputLink></apex:column>
                  <apex:column value="{!s.Contact.Name}"/>
                  <apex:column value="{!s.Subject}"/>
                  <apex:column value="{!s.Priority}"/> 
                  <apex:column value="{!s.CreatedDate}"/> 
                  <apex:column value="{!s.status}"/>      
                  <apex:column value="{!s.createdbyId}"/>
             </apex:pageBlockTable> 
     </apex:pageBlock>
     <apex:pageBlock title="Training Cases">
             <apex:pageBlockTable value="{!TrainingCases}" var="t">
                  <apex:column headervalue="Case"><apex:outputLink value="/{!t.id}">{!t.CaseNumber}</apex:outputLink></apex:column>
                  <apex:column value="{!t.Contact.Name}"/>
                  <apex:column value="{!t.Subject}"/>
                  <apex:column value="{!t.Priority}"/> 
                  <apex:column value="{!t.CreatedDate}"/> 
                  <apex:column value="{!t.status}"/>      
                  <apex:column value="{!t.createdbyId}"/>
                  <apex:column value="{!t.recordtype.id}"/>
         </apex:pageBlockTable>  
     </apex:pageBlock>
</apex:form>   

控制器1:

public with sharing class SupportCasefilter {

    public id accRecId;

    public SupportCasefilter(ApexPages.StandardController controller) {

    accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;

    }

    List<case> supportCases;

    public List<case> getSupportCases() {
        if(accRecId != null) {
        supportCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid 
                        FROM Case 
                        WHERE Record_Type__c='Support' AND account.id=:accRecId];
        }
    return supportCases;
    }    

}

控制器2:

public with sharing class TrainingCasefilter {

    public id accRecId;

    public TrainingCasefilter(ApexPages.StandardController controller) {

    accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;

    }

    List<case> trainingCases;

    public List<case> getTrainingCases() {
        if(accRecId != null) {
        trainingCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid 
                        FROM Case 
                        WHERE Record_Type__c='Training' AND account.id=:accRecId];
        }
    return trainingCases;
    }    

}

2 个答案:

答案 0 :(得分:0)

我建议在将结果传递给pageBlockTable之前,使用SOQL查询在控制器本身中应用记录类型过滤器。

答案 1 :(得分:0)

这是我过去所做的:

1 - 在Controller中创建一个包含有效RecordTypeIds的List<RecordType> validRecordTypes

2 - 使用Controller中的列表Account.Cases过滤对象validRecordTypes

3 - 当您尝试在VisualForce页面中访问Account.Cases时,对象应该是后置过滤的对象