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
Jonathan Crow 10Jonathan Crow 10 

Apex Test Class - When I don't use @istest(SeeAllData=true) I don't get any results back

I am trying not to use (SeeAllData=true), but when I don't use it the test returns no data. When I try to insert data into the record I get an error message that the field cannot be written.

Is there a way around this?
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

If you do not use "@istest(SeeAllData=true)"  and query the records in test class it will not return any details as test class wont have access to records. As you did you have to create the data in test class.

You highlited that you are getting error called "field cannot be written."  it may be because the field may be formula field or auto number . You no need to insert the data with that field it will autocalculate when the record is inserted.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
ravi soniravi soni
hi,
please share your main class.