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
kathybbkathybb 

Problem with referencing a list from an <apex:pageBlockTable>

I'm having a problem getting a pageBlockTable to display a list of Accounts with checkboxes.  It can't seem to find the List I'm asking it to display -- all that shows up is the header row and a blank table.

 

Here is the page code:

<apex:page standardController="Titan_Contract_Orders_Generator__c" extensions="TitanConOrdExtension" >
<apex:sectionHeader title="{!$ObjectType.Titan_Contract_Orders_Generator__c.label} Edit" subtitle="New {!$ObjectType.Titan_Contract_Orders_Generator__c.name}"/>
<apex:form >
<apex:pageBlock title="{!$ObjectType.Titan_Contract_Orders_Generator__c.label} Edit" mode="edit" tabStyle="Titan_Contract_Orders_Generator__c">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="true" title="Basic Information" columns="2" >
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Number_of_Stations_In_Contract__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Renewal_or_Extension__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Who_to_Bill__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Account__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Contract_Start_Date__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Contract_End_Date__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Contract_for__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Date_Submitted__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Status__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Duration_in_Months__c}"/>
<apex:pageBlockSectionItem />
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Date_to_be_Billed__c}"/>
<apex:pageBlockSectionItem />
</apex:pageBlockSection>
<apex:pageBlockSection title="Input Contacts">
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Customer_Contact__c}"/>
<apex:inputField required="true" value="{!Titan_Contract_Orders_Generator__c.Billing_Contact__c}"/>
</apex:pageBlockSection>

<apex:pageBlockSection showHeader="true" title="Notes and Comments">
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Comments_Internal_Use_Only__c}"/>
<apex:outputField value="{!Titan_Contract_Orders_Generator__c.Description__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection showHeader="true" title="Template Information for Orders" columns="2">
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Product__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Price_First_Year__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Orders_Generated__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Price_Second_Year__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Invoice_From__c}"/>
<apex:inputField value="{!Titan_Contract_Orders_Generator__c.Price_Third_Year__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock tabStyle="Titan_Contract_Orders_Generator__c" >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!showAccounts}" value="Show Accounts" />
<apex:commandButton action="{!processSelectAccts}" value="Process Selected"/>
<apex:commandButton action="{!removeSelected}" value="Remove Selected"/>
<apex:commandButton action="{!selectAll}" value="Select All"/>
<apex:commandButton action="{!deselectAll}" value="Unselect All"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>

<apex:pageBlockSection id="ChildAccounts" showHeader="true" title="Select the Accounts involved in this contract" columns="2">
<apex:pageBlockTable width="30%" columns="2" value="{!chooseAccts}" var="acc">
<apex:column width="10%" headerValue="Select">
<apex:inputCheckbox value="{!acc.selected}" />
</apex:column>
<apex:column headerValue="Name" value="{!acc.acct.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Here is the controller for my custom object:

public with sharing class TitanConOrdExtension {
private final Titan_Contract_Orders_Generator__c ext;

public TitanConOrdExtension(ApexPages.StandardController con) {
this.ext = (Titan_Contract_Orders_Generator__c)con.getRecord();
}

public List<tempAcct> childAccounts {get; set;}
public List<tempAcct> chooseAccts {get; set;}
public List<tempAcct> selectedAccts{get;set;}
public List<tempOrder> chooseOrders {get;set;}


public PageReference initAcctList() {
List<Account> childAccounts = new List<Account>();
List<tempAcct> chooseAccts= new List<tempAcct>();

if('{!Contract_for__c}' == 'A Single Station'){
string singleAccount = '{!Titan_Contract_Orders_Generator__c.Account__c}';
string sqry = 'SELECT id, Name FROM Account WHERE id = :singleAccount LIMIT 1';
childAccounts = Database.query(sqry);
chooseAccts.add(new tempAcct(childAccounts[0]));
system.debug('Single Account --- ' + childAccounts[0]);
system.debug('Adding '+ singleAccount + 'to chooseAccts.');
} else {
childAccounts = new List<Account>();
string parentvar = this.ext.Account__c;
string mqry='SELECT id, Name FROM Account WHERE parent.id = :parentVar ORDER BY Name asc LIMIT 200';
childAccounts = Database.query(mqry);
system.debug('childAccounts -- ' + childAccounts.size());
for(Account myAcct : childAccounts){
chooseAccts.add(new tempAcct(myAcct));
system.debug('Adding '+ myAcct + 'to chooseAccts.');
system.debug('ready to exit initAcctList now.');
}
}
return null;
}

public List<tempAcct> showAccounts() {
system.debug('Starting getAccounts');
if(chooseAccts == NULL){
initAcctList();
}
return chooseAccts;
}

}

 

I've left off the other action methods for brevity's sake.

 

Can someone tell me the correct way to reference the chooseAccts List so that the table can find it?  I've tried every way I can think of.  The heap dump shows that the chooseAccts List is being properly populated.

 

Thanks in advance for any help.  This is driving me crazy.  (I'm a relative newby, as you can probably tell).

 

Best Answer chosen by Admin (Salesforce Developers) 
kathybbkathybb

We figured this out locally.  I was inappropriately re-declaring 2 of my public list in methods that returned Null, so of course my lists were showing up on the page as empty.  Removing the errant declarations solved the problem.

All Answers

kathybbkathybb

Sorry, in my haste I left off the last bit of the controller:

 

    public class tempAcct {
            public Account acct {get; set;}
            public Boolean selected {get; set;}

            public tempAcct() {
            }
    
            public tempAcct(Account ao) {
                acct = ao;
                selected = false;
            }
        }

}

 

Thanks again for any help

 

kathybbkathybb

We figured this out locally.  I was inappropriately re-declaring 2 of my public list in methods that returned Null, so of course my lists were showing up on the page as empty.  Removing the errant declarations solved the problem.

This was selected as the best answer