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
etaylor2ketaylor2k 

System.QueryException: List has no rows for assignment to SObject

I am testing my apex class and my test returns a "System.QueryException: List has no rows for assignment to SObject" error. I run the same query in my explorer and it returns the values. What could the problem be?

Best Answer chosen by Admin (Salesforce Developers) 
SeAlVaSeAlVa

Since last release, you need to use 

@isTest(SeeAllData=true)

notation before your test method. (and if you have testmethod keyword in your declaration you have to take it out).

 

Another option is to downgrade the API version to 23.

 

Regards.

 

 

 

All Answers

SeAlVaSeAlVa

Since last release, you need to use 

@isTest(SeeAllData=true)

notation before your test method. (and if you have testmethod keyword in your declaration you have to take it out).

 

Another option is to downgrade the API version to 23.

 

Regards.

 

 

 

This was selected as the best answer
Marcelo CarvalhoMarcelo Carvalho

SeAIVa,

Thank so very much. I am a beginner developer and I lost few days to looking for these ask. Solved!
Tanks again!