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
SalesRedSalesRed 

SOQL Statement Not Executing When Called From Test Class

Hello,

 

I have a SOQL statement in my main class which executes correctly apart from when called from a test class. The SOQL statement returns no results when I execute it from the test class.  If I run the SOQL directly in the salesforce.schema window of my Force.Com IDE the SOQL runs ok and returns results ok.  I run this as a Sys Admin & when I execute the test class I'm logged in as this same user.  The permissions are not set to read only for the Sys Admin user for the fields in my object which I am querying on.   I am executing this in my developer box.

 

Is it possible that Test classes cannot execute a soql query in developer edition?

As the fields are not read only on the object. is there another setting on the object which may block SOQL statements from being run?

 

Thanks.

 

Best Answer chosen by Admin (Salesforce Developers) 
Abhay AroraAbhay Arora

Hi

 

Seems like you have data accessibility issue in your test class you need to use

IsTest(SeeAllData=true)http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htmPlease mark it closed if above solve your issue

All Answers

Abhay AroraAbhay Arora

Hi

 

Seems like you have data accessibility issue in your test class you need to use

IsTest(SeeAllData=true)http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htmPlease mark it closed if above solve your issue

This was selected as the best answer
vishal@forcevishal@force

As per the last updates in Spring'11, test methods will not take data from the Org unless we specify the "SeeAllData = true" attribute. So I guess you are not making any test records for the object on which the query is executed, and hence it returns ZERO results. You need to create data in your test methods.

SalesRedSalesRed

Thank you Vishal & Abhay for your help.

Arpit Sethi 9Arpit Sethi 9
But I read somewhere that its not a good practice to use SeeAllData=true