+ Start a Discussion
Clap MasterClap Master 

SOQL query returning results in Force.com Explorer, but nothing in actual class

I'm usinf a sandbox trying to run a query to get back all open cases that I will then iterate through and do some work on.  Here's my query:

 

SELECT CaseNumber, Status, IsClosed, IsDeleted, Owner.name, LastModifiedDate, Contact.name, Contact.Email FROM Case

 

In the Force.com Explorer, I get all the cases back, but when I run this in a class in my sandbox, I get no results (from the log output, that is).  The below example was a test with pulling from the Account table:

 

09:59:09.617 (1617692000)|SOQL_EXECUTE_BEGIN|[10]|Aggregations:0|select Name from Account
09:59:09.621 (1621556000)|SOQL_EXECUTE_END|[10]|Rows:0

 

I'm pretty sure I'm hitting the same database, and I seem to see this behavior all tables that I've spot checked.

 

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
SLockardSLockard

If you are doing this in a test method, you either need to create test cases/accounts and insert them, or do @isTest(seeAllData=true)

All Answers

SLockardSLockard

If you are doing this in a test method, you either need to create test cases/accounts and insert them, or do @isTest(seeAllData=true)

This was selected as the best answer
Clap MasterClap Master

So if I'm running this through a test class (annotated with @isTest) then I actually need to insert data *IN* the test class before pulling it out?   Will a @isTest class not pull real data from the Sandbox?

SLockardSLockard
Test methods can't see real data, unless you put the seealldata=true at the top. Or yes, you would have to create data in the test method for it to see
Clap MasterClap Master

You, sir, are a gentleman and a scholar.  Thank you.