+ Start a Discussion
jls_74_txjls_74_tx 

PageBlockTable Sort Controller

I'm a newbie to controllers and need some help sorting a pageblocktable.

 

Custom Object:  Apartment__c

Related List:  Unit__c

Result:  Sort Units by Nickname__c

 

Simple VF Page:

<apex:page sidebar="false" showHeader="false" cache="false" standardController="Apartment__c" extensions="sortExtention" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!sortExtension}" var="item">
<apex:column value="{!item.ID}" />
<apex:column value="{!item.Unit_Number__c}" />
<apex:column value="{!item.Nickname__c}" />
<apex:column value="{!item.Available__c}" />
<apex:column value="{!item.Bedrooms__c}" />
<apex:column value="{!item.Bathrooms__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller

public class sortExtension{

public Apartment__c Apt;
public ApexPages.StandardController controller {get; set;}
public List<Unit__c> units; public sortExtension (ApexPages.Standardcontroller c)
{
this.controller = c; Apt = (Apartment__c)Controller.getRecord(); }
public Unit__c [ ] getUnitList()
units = ([Select ID,Unit_Number__c,Available__c,Bathrooms__c,Bedrooms__c,Nickname__c from Unit__c Where Apartment__c.Unit__r = :TC.id ORDER BY Nickname__c]);
return units;}

 

ERROR:  Compile Error: unexpected token: 'units' at line 9 column 7

 

Thank you in advance for your help!

Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande
Can you try using just "unitList" instead of "getUnitList" in your page? If this does not work, try using public List<Unit__c> getUnitList() instead of public Unitlist[] getUnitList().

All Answers

Shailesh DeshpandeShailesh Deshpande
you need to open and close the getUnitList() function. You have not closed it and hence the error.
jls_74_txjls_74_tx

How do I close it?  When I say I'm a newbie...I mean this is my first controller.  ;-)

 
Shailesh DeshpandeShailesh Deshpande
Public unitlist [] getUnitList
{ // this is the opening curly brace

all your logic

return unitlist;
} // this is closing curly brace
jls_74_txjls_74_tx

Got It!  The controller saved but when I try to enter the logic into the VF page I get an error:

 

Error: Unknown property 'Apartment__cStandardController.getUnitList'

 

I know I'm close.....is there a smiley for hitting your head up a wall?  

 

VF Page:

 

<apex:page sidebar="false" showHeader="false" cache="false" standardController="Apartment__c" extensions="sortExtension" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!getUnitList}" var="item">
<apex:column value="{!item.ID}" />
<apex:column value="{!item.Unit_Number__c}" />
<apex:column value="{!item.Nickname__c}" />
<apex:column value="{!item.Available__c}" />
<apex:column value="{!item.Bedrooms__c}" />
<apex:column value="{!item.Bathrooms__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller:

 

public class sortExtension{

public Apartment__c Apt;
public ApexPages.StandardController controller {get; set;}
public List<Unit__c> units; public sortExtension (ApexPages.Standardcontroller c)
{
this.controller = c; Apt = (Apartment__c)Controller.getRecord();}
public Unit__c [ ] getUnitList()
{units = ([Select ID,Unit_Number__c,Available__c,Bathrooms__c,Bedrooms__c,Nickname__c from Unit__c Where Apartment__c = :Apt.id ORDER BY Nickname__c]);
return units;}
}

 

Thank you in advance!

Shailesh DeshpandeShailesh Deshpande
Can you try using just "unitList" instead of "getUnitList" in your page? If this does not work, try using public List<Unit__c> getUnitList() instead of public Unitlist[] getUnitList().
This was selected as the best answer
jls_74_txjls_74_tx

THAT WAS IT!!  {!UnitList}

 

Thank you so much!!  I really appreciate the help.