function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MythiliMythili 

SOQL error on enabling namespace

Hi,
I have enabled namespace in my dev org. Namespace name - LightningMyth.
When I write the following query in any class/trigger, I get the error : : Illegal assignment from List<Account> to List<LightningMyth.Account>
List<Account> acc=[SELECT ID FROM ACCOUNT limit 1];
but the same query works fine in workbench and QueryEditor.
When I changed the query to List<LightningMyth.Account> acc=[select id from LightningMyth.Account limit 1];
I get this error - Compile Error: First SObject of the FROM statement must be a valid SObject type.
I get this issue after enabling namespace and this issue is only with Account object, the SOQL with other standard and custom objects works just fine.
Any help is appreciated!
Amit VaidyaAmit Vaidya
Hi Mythilli,

You don't need to provide prefix of namespace while working with query. You can just use following query:

List<Account> acc=[select id from Account limit 1]

Thanks,
Amit
MythiliMythili
Thanks Amit.
I first queried the way you said but got the following error - : Illegal assignment from List<Account> to List<LightningMyth.Account>.
Whereas the query with other objects like Contact etc. works perfectly fine. 
sobject[] acc=[select id from Account limit 1] - for some strange reason only this query works with Account. I face this issue only with account object. This is wierd!
Ankit Gupta SFDCLearnerAnkit Gupta SFDCLearner
Hi Amit and Mythili,

This is a general schema error, sometimes which came out due to enable of namespace. For overcome we can use below line also.

Schema.Account a =[SELECT Id FROM Account WHERE name = 'contactmeforsfdc'];

Thanks.
Salesforce Learner