System.QueryException: No Such Column - Strange RunAs Behavior with Summer '14?

Ralph -- here is a possible explanation based on a similar experience I had:

If you are generating a SOQL Select in class A using Schema.Describe to get all fields from CustomObject__c resulting in:

Select field1__c, field2__c, field3__c, stdFieldA, stdFieldB  
from CustomOBject__c

Yet, when this query was executed by class B, you get error System.QueryException ‘No such column stdFieldB’

The issue may have to do with versions of each class:

  1. Class A, that generated the SOQL from the Schema.Describe was at VX.0
  2. Class B, that executed the generated SOQL from the Schema.Describe was at VX-n.0
  3. Test Class T, that executed Class A and B was at VX.0

So, the Schema.describe in class A found all the fields known to SFDC version VX.0 which included CustomObject__c.stdFieldB but when executed by a much older class B (version X-n.0), the stdFieldB wasn’t part of the schema at that point in history so QueryException ensued.

Updating class B to VX.0 resolved the issue

Actual use case is blogged here - http://cropredysfdc.com/2014/08/01/versioning-woes-no-such-column-field-is-valid/


Check the deployment status of the object, if it's not set to Deployed you can get this error. It's confusing since the profile permissions look good, but you can't query the object. Note that you can also avoid this issue by adding without sharing to the class which runs the code in system mode which ignores the deployment status.

Gotcha the error can occur on the detail object of a master/detail relationship if the parent is not deployed, so if the object in question is a child object be sure to go up the hierarchy to look for issue with the deployment status