A Gotcha With Standard Controllers

It's not that often I find myself running into issues with the more established parts of the Salesforce.com platform these days, but it does happen. As I've written in the past I'm a big believer in using built-in functionality wherever possible rather than reinventing the wheel.

Visualforce by itself can be very powerful, and even when you do need to use some custom code in an Apex controller you can generally make life easier by utilising a StandardController to do a lot of the legwork for you. Recently I was revisiting an old Visualforce page but I was constantly being greeted with the class field not queried message when viewing the page:

SObject row was retrieved via SOQL without querying the requested field: SomeField__c

What was confusing me was that the field was being referenced in the source for the page, and this should have been enough to ensure it was being queried by the standard controller. I tried using the addFields() method of StandardController but even that didn't get things working which left me scratching my head.

I started poking around at just about everything I could think of and eventually stumbled across the answer: my profile didn't have permission to view or edit the field. Fixing up the Field Level Security quickly restored the page to a working stage, but frankly I'd always assumed that this would be handled in a more graceful manner!

comments powered by Disqus