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
Shawn Reichner 29Shawn Reichner 29 

Visualforce Re rendering issue

Hello Awesome Devs!

I have the following VF Page and Controller.  The VF Page will have a dropdown of territories, and when that dropdown has a value selected, then I woudl like to render the PageBlockSections to show the correct SOQL query on Accounts to bring back the list of records from the controller.

It seems as if any choice in the dropdown calls the Else statement in my controller and always shows those records, and does not change upon selecting a new value, it always stays as the else records.  

Can anyone help me get over the finish line here on this project to conditionally render the proper set of records on the VF page Blocks based on the selection of the drop down territory list on the VF page?

Thank you so much for any help you can provide! 

Shawn

VF Page - 
<apex:page controller="ABMController" showHeader="true" >
    <apex:form id="form">
        <h1></h1><br/>
        <apex:pageMessages />
        <apex:pageBlock mode="inlineEdit" id="Block1" >
        	<apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="SAVE"/>
            </apex:pageBlockButtons>
            
            <span id="idSpan">
            <apex:pageBlockSection title="ABM Assignment Tool" columns="1" id="Details">
           		<apex:selectList value="{!TerritoryID}" size="1">
            		<apex:actionSupport event="onchange" reRender="wrapper1,wrapper2"/>
            		<apex:selectOptions value="{!schedules}"/>
        		</apex:selectList>
            </apex:pageBlockSection>
            </span>
            
            <apex:outputPanel layout="none" id="wrapper1">
            <apex:pageBlockSection title="Assigned Accounts" collapsible="false" columns="5" rendered="{!TerritoryID != null}">
            	<apex:pageBlockTable value="{!accts}" var="a" border="1">
                    <apex:column headervalue="Account Name">
                        <apex:outputLink value="/{!a.Id}">{!a.name}</apex:outputLink>
                    </apex:column>
                    <apex:column headerValue="Owner Name">
                        <apex:inputField value="{!a.ownerId}"/>
                    </apex:column>
                    <apex:column value="{!a.Armor_Territory__c}"/>
                    <apex:column value="{!a.Status__c}"/>
                    <apex:column value="{!a.Average_TAM_Score__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            </apex:outputPanel>
        
        
        <apex:outputPanel layout="None" id="wrapper2">
            <apex:pageBlockSection title="Un-Assigned Accounts" collapsible="false" columns="5" rendered="{!TerritoryID != null}" >
            	<apex:pageBlockTable value="{!unassigned}" var="a" border="1">
                    <apex:column headervalue="Account Name">
                        <apex:outputLink value="/{!a.Id}">{!a.name}</apex:outputLink>
                    </apex:column>
                    <apex:column headerValue="Owner Name">
                        <apex:inputField value="{!a.ownerId}"/>
                    </apex:column>
                    <apex:column value="{!a.Armor_Territory__c}"/>
                    <apex:column value="{!a.Status__c}"/>
                    <apex:column value="{!a.Average_TAM_Score__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller - 
 
public class ABMController {

    public SelectOption[] getSchedules() {
        return new SelectOption[] {new SelectOption('Value1', '--Select a Territory--'),
            new SelectOption('Value2', 'Northwest'), new SelectOption('Value3', 'Southwest'), new SelectOption('Value4', 'Upper South Central')};
    }
    
    public String TerritoryID {get; set;}
    public List<Account> accts {get; set;}
    public List<Account> unassigned {get; set;}
    User sapi = [SELECT Id,Name FROM User WHERE FirstName = 'SalesStaff' LIMIT 1];
    String TerrName = TerritoryID;
    
    public ABMController(){
        
        if(TerrName == 'Value2'){
            accts = new List<Account>();
            unassigned = new List<Account>();
            accts = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Northwest' AND OwnerId !=: sapi.Id ORDER BY OwnerId ASC LIMIT 40];
            unassigned = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Northwest' AND OwnerId =: sapi.Id AND Status__c = 'Not Active' ORDER BY Average_TAM_Score__c DESC LIMIT 10];
        } else If(TerrName == 'Value3') {
            accts = new List<Account>();
            unassigned = new List<Account>();
            accts = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Southwest' AND OwnerId !=: sapi.Id ORDER BY OwnerId ASC LIMIT 40];
            unassigned = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Southwest' AND OwnerId =: sapi.Id AND Status__c = 'Not Active' ORDER BY Average_TAM_Score__c DESC LIMIT 10];
        } else {
            accts = new List<Account>();
            unassigned = new List<Account>();
            accts = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Upper South Central' AND OwnerId !=: sapi.Id ORDER BY OwnerId ASC LIMIT 40];
            unassigned = [SELECT ID, NAME, OwnerId, Armor_Territory__c, Status__c,Average_TAM_Score__c FROM Account WHERE Armor_Territory__c = 'Upper South Central' AND OwnerId =: sapi.Id AND Status__c = 'Not Active' ORDER BY Average_TAM_Score__c DESC LIMIT 10];
        }
        
        
    }
    
    
    
    public PageReference showAccounts() {
        system.debug('EXECUTED');
        return null;
    }
    
    public PageReference save(){
        update accts;
        update unassigned;
        PageReference congratsPage = Page.ABMPage;
  		congratsPage.setRedirect(true);
  		return congratsPage;
        
    }

    
}

 
E Jayaraman IyerE Jayaraman Iyer
Hi Shawn,

It seems you have not added any action on your apex:actionSupport. You have written logic for rendering inside the constructor, so basically that logic will only be executed on load of your page and not on change of picklist value. Move the logic inside any method and add that method into action in actionSupport. This should solve your issue if rest of the logic is correct.

Thanks