+ Start a Discussion
Srinivas223Srinivas223 

Query is getting results in Devconsole but throwing exception in test class. Any Ideas?

A simple query [select id from customObject__C] is working in Dev Console but throwing 
System.QueryException: List has no rows for assignment to SObject
Please let me know if you have any ideas on this.

Thank you!
Jayant DasJayant Das
How are you assigning the results of the query? Additionally how are you executing this in Dev Console? For the query you have mentioned here, it needs to be assigned to a list of the custom objects, as:
List<CustomObject__c> = [select id from CustomObject__c];
Waqar Hussain SFWaqar Hussain SF
The error is showing because the query is retruning no result. 

See
https://help.salesforce.com/articleView?id=000159853&type=1