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
Lee_CampbellLee_Campbell 

Impossible exception (no rows)

A query I'm running in a test:

 

Milestone1_Project__c x = [select id from Milestone1_Project__c limit 1];

Gives the "list has no rows" error, which is impossible, as there definitely exists some "Milestone1_Project__c" records. I have absolutely no idea why this is happening. Can anyone shed any light on the subject?

 

(I know it's common practice to create new records for use in a test, but I don't want to, for reasons I'll elaborate if anyone asks.)

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Tests don't see all organization data by default since APi version 24.  You need to have the following annotation:

 

IsTest(SeeAllData=true)

 more info at:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm

All Answers

bob_buzzardbob_buzzard

Tests don't see all organization data by default since APi version 24.  You need to have the following annotation:

 

IsTest(SeeAllData=true)

 more info at:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm

This was selected as the best answer
Lee_CampbellLee_Campbell

Ah... cool. Thanks, Bob!