SObject row was retrieved via SOQL without querying the requested field

by - 11:46 AM

Salesforce have provided getrecord() method to pull field of a given object. This leaves the impression that all fields would be queried on back-end and could be assigned to properties (get; set;) to display on visualforce page, but often people get confused, clearly salesforce have recently update their documentation for this method

Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression.

On Opportunity object, I used 'IsClosed' field to check for a condition in controller extension and I ended up in this exception

SObject row IsClosed was retrieved via SOQL without querying the requested field

Here is something I was trying to achieve

My Controller Logic

My VisualForce Page Logic

I received this error

So in this case, I added the missing field and with the attribute 'rendered=false' on visualforce page and this fixed my problem

Here is my fixed code : Just add the missing field on VisualForce Page shown in exception than on Controller

You May Also Like