I am creating a Visualforce page and I have a section where I want to add in a Select List with three values and based on the value that is selected I want it to display a specific Page Block Section on the page and I just cannot seem to get it to work. I think I am very close and that I am just missing something and would appreciate any and all help.

Here is the Visualforce code

<apex:page controller="CommunityQuoteNowController" showHeader="true" sidebar="false" lightningStylesheets="true">
        <apex:outputPanel id="messagePanel">
            <apex:pageMessages />
        <!-- Quote Now Form -->
        <apex:form id="quoteNowForm" >
            <apex:pageBlock title="Quote Now">
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton action="{!GetRates}" value="Get Rates"/>
                    <apex:commandButton action="{!clearPage}" value="Clear" />
                <apex:pageBlockSection >
                    <apex:inputField label="Customer Profile" value="{!load.rtms__Customer__c}" />
                    <apex:selectList value="{!selectedMode}" title="Select" multiselect="false" size="1" id="selectModes" label="Mode">
                        <apex:selectOptions value="{!ModesList}" />
                    <apex:inputField label="Total Weight" value="{!load.rtms__Total_Weight__c}" />
                <apex:pageBlockSection title="Details" columns="2">
                    <apex:inputField label="Ship Date" value="{!load.rtms__Order_Date__c}" />
                    <apex:inputField label="Payment Terms" value="{!load.rtms__Payment_Terms__c}" />
                    <apex:inputField label="Origin Zip Code" value="{!originStop.rtms__Postal_Code__c}" />
                    <apex:inputField label="Destination Zip Code" value="{!destinationStop.rtms__Postal_Code__c}" />
                <hr />
                <apex:pageBlockSection columns="1">
                    <apex:selectList value="{!selectedFreightDetail}" title="freightDetails" multiselect="false" size="1" id="selectFreightDetails" label="Freight Details" >
                        <apex:selectOptions value="{!FreightDetails}" />
                        <apex:actionSupport event="onchange" reRender="freightDetailsWrapper" />
                <apex:outputPanel layout="none" id="freightDetailsWrapper" >
                    <apex:pageBlockSection columns="2" id="ClassAndWeight" rendered="{!IF(selectedFreightDetail != 'Class_and_Weight',True,False)}">
                        <apex:repeat value="{!lineItems}" var="items">
                            <apex:inputField label="NMFC Class" value="{!items.rtms__NMFC_Class__c}"/>
                            <apex:inputField label="Weight (lbs)" value="{!items.rtms__Weight__c}"/>
                    <apex:pageBlockSection columns="4" id="Density"  rendered="{!IF(selectedFreightDetail = 'Density',True,False)}">
                        <apex:repeat value="{!lineItems}" var="items">
                            <apex:inputField label="Length (in)" value="{!items.rtms__Length__c}"/>
                            <apex:inputField label="Width (in)" value="{!items.rtms__Width__c}"/>
                            <apex:inputField label="Height (in)" value="{!items.rtms__Height__c}"/>
                            <apex:inputField label="Weight (lbs)" value="{!items.rtms__Weight__c}"/>
                    <apex:pageBlockSection columns="3" id="Pallet" rendered="{!IF(selectedFreightDetail = 'Pallet',True,False)}">
                        <apex:repeat value="{!lineItems}" var="items">
                            <apex:inputField label="Handling Units" value="{!items.rtms__Handling_Units__c}"/>
                            <apex:inputField label="Handling Unit Count" value="{!items.rtms__Handling_Unit_Count__c}"/>
                            <apex:inputField label="Weight (lbs)" value="{!items.rtms__Weight__c}"/>
                <apex:commandButton value="Add Line Item" Action="{!AddRow}" immediate="true" id="addRowButton"/>

And here is my controller

public class CommunityQuoteNowController {

// Variables
public rtms__Load__c load { get; set; }
public rtms__Stop__c originStop { get; set; }
public rtms__Stop__c destinationStop { get; set; }
public List<rtms__Load__c> loadList { get; set; }
public List<rtms__LineItem__c> lineItems { get; set; }
public String selectedMode { get; set; }
public List<SelectOption> availableModes { get; set; }
public String selectedFreightDetail { get; set; }
public List<SelectOption> options { get; set; }

public rtms__Load__c getLoad() {
    return load;

public CommunityQuoteNowController() {
    load = new rtms__Load__c();
    originStop = new rtms__Stop__c();
    destinationStop = new rtms__Stop__c();
    lineItems = new List<rtms__LineItem__c>();

public PageReference AddRow() {
    lineItems.add(new rtms__LineItem__c());
    return null;

public List<selectOption> getModesList() {
    List<rtms__Mode__c> modes = new List<rtms__Mode__c>();

    modes = [Select Id,name from rtms__Mode__c];

    List<SelectOption> availableModes = new List<SelectOption>();

    availableModes.add(new SelectOption('','--None--'));

    for(rtms__Mode__c m : modes) {
        availableModes.add(new SelectOption(m.Id,m.Name));
    return availableModes;

public List<selectOption> getFreightDetails() {
    List<SelectOption> options = new List<SelectOption>();

    options.add(new SelectOption('Class_and_Weight','Class and Weight'));
    options.add(new SelectOption('Density','Density'));
    options.add(new SelectOption('Pallet','Pallet'));

    return options;

/* Attempt at displaying a total weight for line items
public Decimal getTotalWeight(){
    Decimal totalWeight = 0;
    for(rtms__LineItem__c li : lineItems) {
        totalWeight += (li.rtms__Weight__c);
    return totalWeight;
} */

public PageReference clearPage() {
    PageReference newpage = new PageReference(System.currentPageReference().getURL());
    return newpage;

public PageReference GetRates() {
    load.rtms__Mode__c = selectedMode;
    upsert load;
    if(load != null) {
        originStop.rtms__Load__c = load.Id;
        originStop.rtms__Number__c = 1;
        originStop.rtms__Is_Pickup__c = True;
        upsert originStop;
    if(load != null) {
        destinationStop.rtms__Load__c = load.Id;
        destinationStop.rtms__Number__c = 2;
        destinationStop.rtms__Is_Dropoff__c = True;
        upsert destinationStop;
    List<rtms__LineItem__c> items = new List<rtms__LineItem__c>();
    if(load != null) {
        for(rtms__LineItem__c i : lineItems) {
            i.rtms__Load__c = load.Id;
            i.Name = 'Line Item From Quote';
            i.rtms__Item_Description__c = 'From Quote';
            i.rtms__Pickup_Stop__c = originStop.Id;
            i.rtms__Delivery_Stop__c = destinationStop.Id;
    if(items != null) { 
        upsert lineItems;
   return null;

Take a closer look at your code wherever you are loading the select options (i.e., filter values). For example,

options.add(new SelectOption('','Class and Weight'));
options.add(new SelectOption('','Density'));
options.add(new SelectOption('','Pallet'));

The label string in the constructor definition SelectOption(value, label) is displayed as one of the filter options to the user and value string is returned to the controller when the user selects an option. In your code, you are passing a valid label string, but an empty string for all value. So when you select an option, empty value is passed back to the controller.

Now, look the apex:pageBlockSection code. For example,

<apex:pageBlockSection columns="2" id="ClassAndWeight" rendered="{!IF(selectedFreightDetail = 'Class And Weight',True,False)}">

Since, your filter selection passed back an empty string, selectedFreightDetail will hold this empty value and the IF condition in apex:pageBlockSection will always evaluate to false. Hence, the re-rendering of the component doesn't display anything.

Note: Ensure that the value string passed to SelectOption constructor and value used in the apex:pageBlockSection match exactly (case sensitively). As a best practice, don't use spaces in the value strings and replace them with _ (or anything other char of your choice).

  • Okay, thanks for pointing this out. I was sure that I was missing something small. I updated the values for the Select Options and then copy and pasted them into the appropriate Page Section reRenders but they are still not loading so I feel like maybe I am missing something else. Any other thoughts? – cmmoutes13 Oct 20 '20 at 15:49
  • Could you post the update code snippet? Have you checked if lineItems is populated before you change the filter value? Easiest way is to remove the IF condition in pageBlockSection and check if you are able to see all the block sections with values populated. – arut Oct 20 '20 at 15:59
  • Okay, I updated all of my code in the original post. – cmmoutes13 Oct 20 '20 at 16:06
  • Also, I updated the code within the IF's to say selectedFreightDetail = Null instead of the values and they all loaded in. So that variable is still not getting a value.... Any thoughts @arut ? – cmmoutes13 Oct 20 '20 at 17:02
  • Your code works fine in my dev org (Although, I had to comment out a lot of code and retain only the code relevant to filter options and page block section; and use Account object instead of rtms__LineItem__c). Based the following line in your code {!IF(selectedFreightDetail != 'Class_and_Weight',True,False)}, the Class and Weight block is always displayed, while the other 2 sections are toggled based on user selection. Are none of the page block sections displayed for you (regardless of change in selected filter option)? – arut Oct 20 '20 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.