3

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">

2 Answers 2

3

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">
2
  • really?!?! It worked. do all getter's need to start with get?
    – tjcinnamon
    Jan 26, 2016 at 15:54
  • 1
    @tjcinnamon yes that needs to be start with get..
    – Ratan Paul
    Jan 26, 2016 at 16:04
4

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.

2
  • 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, 2016 at 17:19
  • Only if the data is changing between interactions, which seems unlikely.
    – Adrian Larson
    Jan 26, 2016 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .