Overview: "No such column" error presents itself when I wrap valid SOQL in Apex Class. I am familiar with what this error means, but in this situation I don't feel as though the error is justified.
1) The following operations work exactly as expected and return rows:
Query editor:
Select Id, AccountId, Territory2Id from Opportunity
Execute Anonymous:
List<Opportunity> oList = new List<Opportunity>([Select Id, AccountId, Territory2Id from Opportunity]);
2) This is where it gets weird. When I copy paste my Apex from execute anonymous console and wrap in a dead-simple class, the save is not allowed.
Attempt to create a dead-simple Apex Class:
public with sharing class SomeClass {
List<Opportunity> oList = new List<Opportunity>([Select Id, AccountId, Territory2Id from Opportunity]);
}
3) Upon attempting to save the class, I observe "No such column 'Territory2Id' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names."
Recap: FLS is fine, functional SOQL query proves the existence of the column, and Execute Anonymous proves the validity of the Apex. What could be the issue, what am I missing?
Thanks for any insights.
Territory2Id
was a reasonably recent addition to the schema