Question

I have the following visualforce page and need to filter either the related lists or the pageblocktables by the case.recortype or case.recordtype.id field. Can anyone guide me to finding out how to do this? Thanks

<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>

Update: This is What I actually ended up doing:

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>   

controller1:

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;
    }    

}

controller2:

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;
    }    

}
Was it helpful?

Solution

Here's what I have done in the past:

1 - Create a List<RecordType> validRecordTypes that contains valid RecordTypeIds in the Controller

2 - Filter your objects Account.Cases using the the list validRecordTypes in the Controller.

3 - When you try to access Account.Cases in the VisualForce page, the objects should be post-filtered objects

OTHER TIPS

I'd recommend applying the record type filter within the controller itself using a SOQL query before passing the results into the pageBlockTable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top