2

So I have a standard controller and an extension that I'm trying to use to call back a list from a different object to use in a PageBlockTable. In the visualforce page I declare my standard controller and extension:

<apex:page standardController="APM__c" extensions="APM_OpenChart" recordSetVar="apps">

Later on in my PageBlockTable I'm trying to pass the list from the extension using this class:

public with sharing class APM_OpenChart {

    public APM_OpenChart(ApexPages.StandardSetController stdController) {}

    public List<APM__c> spoofgrid(){
         List<APM__c> results = database.query('SELECT Name , BV_Result__c ,TV_Result__c FROM APM__c Limit 1');
        return results;
    }
}

However, when I attempt to pass the values I get an unknown property error when trying to use the list from the extension.

<apex:pageBlockTable value="{!APM_OpenChart.spoofgrid}" var="token">
1

Change you method to getspoofgrid. Add get so it will be accessible in page

public List<APM__c> getspoofgrid(){
         List<APM__c> results = database.query('SELECT Name , BV_Result__c ,TV_Result__c FROM APM__c Limit 1');
        return results;
    }

And in VF

<apex:pageBlockTable value="{!spoofgrid}" var="token">
  • really?!?! It worked. do all getter's need to start with get? – tjcinnamon Jan 26 '16 at 15:54
  • 1
    @tjcinnamon yes that needs to be start with get.. – Ratan Paul Jan 26 '16 at 16:04
3

Your properties need a getter to be defined. While the approach mentioned by @Ratan will work, you can also "lazy load" your results in a way that does not consume a new query every time. Here is a discussion on how these methods work.

Alternative getter/setter patterns:

public List<APM__c> spoofGrid { get; private set; }
public List<APM__c> spoofGrid
{
    get
    {
        // run query every time
        // don't need a setter
    }
}
public List<APM__c> getSpoofGrid()
{
    // this is identical (in VF) to the above
}

Lazy Load:

public List<APM__c> spoofGrid
{
    get
    {
        if (spoofGrid == null)
        {
            spoofGrid = Database.query(someSoql);
        }
        return spoofGrid;
    }
    private set;
}

You need a setter (which should be private) if you want to lazy load because you need to cache the results in your property.

  • I think I need a query every time because i need at least 1 record to return to "spoof" the pageblocktable. Or is that not the case? – tjcinnamon Jan 26 '16 at 17:19
  • Only if the data is changing between interactions, which seems unlikely. – Adrian Larson Jan 26 '16 at 17:30

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.