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
nikvmnikvm 

Test class concern

Hello Alll,

 

I have been reading the force.com manual .

I came accross below line 

 

"Starting with Apex code saved using Salesforce.com API version 24.0, test methods don’t have access by default to pre-

existing data in the organization."

 

link http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

What does this mean? Does it mean I can't write a soql inside my test class. 

Please help me clarify my understanding.

 

Thanks a ton!!!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ibtesamibtesam

Hi Nik,

 

"Starting with Apex code saved using Salesforce.com API version 24.0, test methods don’t have access by default to pre-

existing data in the organization."

 

Meaning of this statment is this,

say you have created 5 accounts, in your org and you want to query them in your test class with class version 24.0, those account records will not be visible.

 

In short, test class has become a black box, once you are inside it,you cant see outside that class. meaning you need to create records/data in your test class and then use it to test the scenarios.

 

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

 

if you see the above link, the records are created with "insert" DML statement, and as i said it is a black box meaning you cant see that data created by test class in your org,

Test class data and your org data is totally isolated.

 

Hope you understood!

All Answers

ibtesamibtesam

Hi Nik,

 

"Starting with Apex code saved using Salesforce.com API version 24.0, test methods don’t have access by default to pre-

existing data in the organization."

 

Meaning of this statment is this,

say you have created 5 accounts, in your org and you want to query them in your test class with class version 24.0, those account records will not be visible.

 

In short, test class has become a black box, once you are inside it,you cant see outside that class. meaning you need to create records/data in your test class and then use it to test the scenarios.

 

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

 

if you see the above link, the records are created with "insert" DML statement, and as i said it is a black box meaning you cant see that data created by test class in your org,

Test class data and your org data is totally isolated.

 

Hope you understood!

This was selected as the best answer
nikvmnikvm

Thanks for this explanation!