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
ApexGuyApexGuy 

Visual Force controller extension's access through getRecord()

When an extension to a VisualForce controller uses standardcontroller.getRecord(), it seems only to get access to the fields of the sObject that the standard controller retrieved in its SOQL query.

 

The standard controller only seems to retrieve those fields requested of it on the VisualForce page. In other words, the standard controller seems to make a SOQL query that includes only those fields asked of it, and that does not include those fields requested of the extension.

 

My question is how is it that the standard controller knows what fields are asked of it on the VisualForce page? How does it know what fields to query for in the SOQL query? The fields that the standard controller will have to make a SOQL query for are not passed in through the Page Reference, are they? Is there another mechanism at work?

ThomasTTThomasTT
I saw this in the manual somewhere (sorry, I'm on a bus now), fields used in VF page markup are also queried automatically. So, it's saying that you need to use outputfield with rendered=false or display=none. I was surprized that that's the official solution.
ThomasTT
XactiumBenXactiumBen
Or you could just do another query on your record in the controller extension...
BritishBoyinDCBritishBoyinDC

Now you mention it, I have experienced this behavior as well - I could only use the fields in the extension if I included them in a hidden section on the page, as described by by Thomas below...

ThomasTTThomasTT

I do that, too - query it again for myself.

I'm not sure the automatic query works for child objects (e.g. account.RecordType.Name). Especially in triggers, I query the target objects again for my self to use those child objects.

But it is really wasting resource if it is about just a field, and hidden output fields are the official way, so... here we go.

ThomasTT