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

Hi All, is it possible we can write a soql querys in test class

Hi All,
is it possible we can write a soql querys in test class .

Mani RenusMani Renus

Yes, it is possible!! but you need write SeeAllData=true(as like below) for access org data.


Rahul SharmaRahul Sharma
Ideally you should create your own test data!
Sorry am not getting your point can you pls domonstrate on that
Rahul SharmaRahul Sharma
You could learn more on writing test classes in Awesome Salesforce Trailhead - Getting Started with Apex Unit Tests ( and Creating Test Data for Apex Tests (
jyothsna reddy 5jyothsna reddy 5
Hi Viswsanath,
    Yes,it is possible to write  a soql in test class using @IsTest(SeeAll=True) Annotation.
Annotate your test class or test method with IsTest(SeeAllData=true) to open up data access to records in your organization.

Considerations for the IsTest(SeeAllData=true) Annotation:
  • If a test class is defined with the isTest(SeeAllData=true) annotation, this annotation applies to all its test methods whether the test methods are defined with the @isTest annotation or the testmethod keyword.
  • The isTest(SeeAllData=true) annotation is used to open up data access when applied at the class or method level. However, using isTest(SeeAllData=false) on a method doesn’t restrict organization data access for that method if the containing class has already been defined with the isTest(SeeAllData=true) annotation. In this case, the method will still have access to all the data in the organization. 
    For more information please follow the below link