+ Start a Discussion
LaurenP6777LaurenP6777 

Filter Related List using Visualforce Extension on Standard Controller

I am using the standard Opportunity controller for the Opportunity VF page. I would like to break out Related Opportunities into two related lists. I have heard that I can do this using an extension but I can't seem to figure it out even using other people's examples. 

 

I  want it to be like this:

 

Active Related Opportunities {Opportunity.Active=true}

 

Inactive Related Opporutnities {Opporutunity.Active=false}

 

The visualforce is simple:

<apex:page standardController="Opportunity" showHeader="true" tabStyle="opportunity" >
<apex:relatedList subject="{!opportunity.id}" list="Opportunities__r" pageSize="55" />
</apex:page>

 

Can someone show me how to write the controller extension and put it in the visualforce? Thanks!!!!

sivaextsivaext

Hi 

 

it is not possible by using related list tag.

 

 In extension controller , query all opportunities and create two different lists based on your conditions. 

 

 Use apex:pageBlocktable  tag to display two display both lists. 

LaurenP6777LaurenP6777

Could you give me a small example of how to return a list in a controller extension?

sivaextsivaext

Hi

 

 

Page:

 <apex:page standardController ="Account" extensions="AccExtensions">

   <apex:form>

<apex:pageBlock>

      //all accounts fields information

</apex:pageBlock>

<apex:pageBlock>

   <apex:pageBlockTable value={!type1} var="ty">

       <apex:column> 

               <apex:outputField value="{!ty.name}" />

       </apex:column>

    //repeat for remaining fields

</apex:pageBlockTable>

 

  <apex:pageBlockTable value="{!type2} var="ty1">

   

 <apex:column> 

               <apex:outputField value="{!ty1.name}" />

       </apex:column>

    //repeat for remaining fields

</apex:pageBlockTable>

</apex:pageBlock>

   

</apex:form>

 </apex:page>

 

Controller:

  public class AccExtensions{

      Public List<Opportunity> opp1{get;set;}

      public List<Opportunity> type1{get;set;}

      public List<Opportunity> type2{get;set;}

       public AccExtensions(ApexPages.StandardController controller) {

          opp1=[select id , name from opportunity where accountID=:ApexPages.currentPage().getParameters().get(id)];

          for(Opportunity op:opp1) {

 

             if(op. fieldName ="type") {

 

                type1.add(op);

}

else {

 

          type2.add(op);

}

}

}

}

 

Note: This is sample code