You need to sign in to do that
Don't have an account?
Bryan Leaman 6
Why is it this soql query works in query editor but not in apex
I have a simple SOQL query that I can run using developer console or workbench and it runs fine. But when I copy/paste it into anonymous apex it complains the the field I'm requesting does not exist. How can that be? I am running this as a system admin and I *do* have authority to the field.
Here's a screenshot showing the query in developer workbench side-by-side with anonymous apex and the results.
Here's a screenshot showing the query in developer workbench side-by-side with anonymous apex and the results.
SOQL query editor -- works:
select Id, Name, dealer__Region__c
from dealer__Dealer_Location__c
where dealer__Region__c='Florida'
Anonymous Apex -- doesn't like the field dealer__Region__c:
System.debug([
SELECT Id, Name, dealer__Region__c
FROM dealer__Dealer_Location__c
where dealer__Region__c='Florida'
]);
Results in "Execute Anonymous Error" box:
Line: 1, Column: 14
SELECT Id, Name, dealer__Region__c ^ ERROR at Row:2:Column:22 No such column 'dealer__Region__c' on entity 'dealer__Dealer_Location__c'. 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.
If you try "SELECT Id FROM dealer__Dealer_Location__c" in Salesforce does it show anything? If so, slowly add the other columns back in and then the filter.
Try typing out the field names instead of copy/paste if you previously did that.
Lastly, if it still isn't working, I would double-check to make sure the field does exist in the environment you are testing in (I know you've probably already done this, just covering bases :-) ).
It seems this fails any time we have a custom field named the same as a managed field in the object (apart from the namespace prefix) -- I can't query the managed field name in Annonymous Apex, but I can query it using the query tools of developer console and workbench.
I've tried different API levels in workbench and it seems to act the same. I've never seen this before, but it's just slightly possible that I'd not tried it before. Our managed package provider created custom fields for us and then later added the same field to the managed package. I haven't seen any issues in regular code -- classes, triggers, VF, lightning -- so far just in anonymous apex.
This is *so* bizarre!