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
Jennifer BERNARDJennifer BERNARD 

SOQL request from test does not have the same result than request sent from debug

Hello everyone,

When I set mock up data in a test class, a trigger is fired and this request is sent in its process :
SOQL_EXECUTE_BEGIN [15]|Aggregations:0|SELECT id FROM Pricebook2 WHERE Name LIKE '%Standard%'
SOQL_EXECUTE_END [15]|Rows:0
But when I send this request in the Debug window I get this:
SOQL_EXECUTE_BEGIN [1]|Aggregations:0|SELECT id FROM Pricebook2 WHERE Name LIKE '%Standard%'
SOQL_EXECUTE_END [1]|Rows:1
Is it a profile issue ? Or a bug ? Or something else ? The trigger process failed because it cannot find any records from Pricebook2 table.
 
Best Answer chosen by Jennifer BERNARD
AbhinavAbhinav (Salesforce Developers) 
Hi Jennifer,

Test classes by default cannot access real data. It can access only the test data created within the test class. 

Please refer below for details:

https://salesforce.stackexchange.com/questions/102455/query-works-in-anonymous-window-but-fails-in-test-class

If it helps please mark it as best answer.

Thanks!