function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maeze AhlersMaeze Ahlers 

How can you specify a specific list for 3 different columns of pageblocksections?

I'm trying to create a page that shows three columns each referencing a specified list (that will eventually be customizeable) of opportunities. Basically, I need to assign a specific listview to a pageblocksection. I've attached my code and a screenshot any help would be great!!User-added image
<apex:page standardcontroller="opportunity" recordsetvar="opportunities" id="pageopp" >
 <apex:form >
  
   <apex:pageblock title="pageblocktitle">
      <apex:pageblockbuttons >
       <apex:commandButton value="Save" action="{!save}"/>
       <apex:commandButton value="Quick Save" action="{!save}"/>
      </apex:pageblockbuttons> 
      <apex:panelgrid columns="4">
    
     <apex:outputPanel >
      <apex:pageblock title="pageblocktitle1">
       <apex:pageblocksection >
        <apex:repeat value="{!opportunities}" var="opp" id="rep">
       <apex:pageblocksection title="{!opp.name}">
       </apex:pageblocksection> 
        </apex:repeat>
       </apex:pageblocksection>
     </apex:pageblock>
    </apex:outputpanel>
    
    <apex:outputPanel >
      <apex:pageblock title="pageblocktitle1">
       <apex:pageblocksection >
        <apex:repeat value="{!opportunities}" var="opp" id="rep">
       <apex:pageblocksection title="{!opp.name}">
       </apex:pageblocksection> 
        </apex:repeat>
       </apex:pageblocksection>
     </apex:pageblock>
    </apex:outputpanel>
    
      <apex:outputPanel >
      <apex:pageblock title="pageblocktitle1">
       <apex:pageblocksection >
        <apex:repeat value="{!opportunities}" var="opp" id="rep">
       <apex:pageblocksection title="{!opp.name}">
       </apex:pageblocksection> 
        </apex:repeat>
       </apex:pageblocksection>
     </apex:pageblock>
    </apex:outputpanel>
    
    
   </apex:panelgrid>
  </apex:pageblock>
  
 </apex:form>
</apex:page>
James LoghryJames Loghry

Hi Maez,

You have a few different options here.  Declaritively, you could simply have the users utilize the existing list view tab classic or lightning experience and toggle between one of the three or more list views.

If you're getting ready to switch to Lightning Experience, then you could also just add a related list component to the record detail page of the parent record (whether it's an account or some other object).  The related lists would then allow you to filter by a different list view, giving you similar functionality to what your Visualforce page would look like.

Next, if you're keen on keeping the Visualforce page, then you could use a series of repeats and the "rendered" attribute to determine which list to display when.

Last, and proably most likely, you're looking at extending your Visualforce page with an Apex controller.  In the Apex controller, you'd take the recordSetVar and determine which "list views" or criteria to display in code, and then render those lists back in Visualforce.  I took a quick stab at this example.

In my example, I'm filtering by one of three stages (Closed Won, Closed Lost, and Prospecting).  Depending on the stage, I'm adding the opportunities to one of the three lists and then showing it in Visualforce.

 

Here's the Apex extension controller:

public class OpportunityListViewCtrl{
    
    //List of opportunity view wrapper classes.  These make up the columns in our VF page.
    public List<OpportunityView> opportunityViews {get; set;} 
    
    //Constructor for the Standard Set Controller extension class
    public OpportunityListViewCtrl(ApexPages.StandardSetController ssc){
   		this.opportunityViews = new List<OpportunityView>();
        
        //Construct a map of Opportunities, which gives us easy access to the Id of the records.
        Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>((List<Opportunity>)ssc.getRecords());
        
        //Since the StageName does NOT come back via the StandardSetController, we need to re-query the opportunities.
        List<Opportunity> opportunities = [Select Id,Name,StageName From Opportunity Where Id in :oppMap.keySet()];
        
        //Construct a map of opportunity views.  These will make the columns in our VF page.
        Map<String,OpportunityView> viewMap = new Map<String,OpportunityView>{
            'Prospecting' => new OpportunityView('Prospecting')
            ,'Closed Won' => new OpportunityView('Closed Won')
            ,'Closed Lost' => new OpportunityView('Closed Lost')
        };
          
        //Iterate through the re-queried opportunities.
        for(Opportunity opp : opportunities){
            //Adjust this to whatever criteria makes up your views.
            //First view is all 
            if(viewMap.containsKey(opp.StageName)){
                viewMap.get(opp.StageName).opportunities.add(opp);
            }
        }
        
        //Grab the list of opportunity views from the map to render in Visualforce.
        this.opportunityViews = viewMap.values();
    }
    
    //Wrapper class that contains a display name and the list of opportunities to display.
    public class OpportunityView{
        public String viewName {get; set;}
        public List<Opportunity> opportunities {get; set;}
        
        public OpportunityView(String viewName){
            this.viewName = viewName;
            this.opportunities = new List<Opportunity>();
        }
    }

}



And here is the Visualforce page for the example:
<apex:page standardcontroller="opportunity" recordsetvar="opportunities" id="pageopp" extensions="OpportunityListViewCtrl">
<apex:form >
	<apex:pageblock title="Some Title Goes Here">
   		<apex:pageblockbuttons >
   			<apex:commandButton value="Save" action="{!save}"/>
   			<apex:commandButton value="Quick Save" action="{!save}"/>
   		</apex:pageblockbuttons>
     
   		<apex:pageBlockSection columns="{!opportunityViews.size}">
       
    		<apex:repeat value="{!opportunityViews}" var="view">
     			<apex:pageBlock title="{!view.viewName}">
             		<apex:pageBlockTable value="{!view.opportunities}" var="opp" columns="1" title="View 1">
               			<apex:column >{!opp.Name}</apex:column>
             		</apex:pageBlockTable>
     			</apex:pageBlock>
            </apex:repeat>
     	</apex:pageBlockSection>
    </apex:pageblock>
</apex:form>
</apex:page>

Hope that helps
Maeze AhlersMaeze Ahlers
Hi James! 

Thank you for all of the info. I think the extension controller might be a little above my pay grade. If I were to do the second option can you give me an example of how I could modify my current code to fit that? Thank you in advance!