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
Pascal TPascal T 

Testing method do not see my Pricebook records while it is working on manual test

Hello,

 

In my test method it looks like there is no pricebook record I can use.

The following code returns the value 0 while I have 4 Pricebook records in my sandbox.

 

System.debug('There is '+[SELECT COUNT() FROM Pricebook2]+ ' Pricebook(s)');

 

 

Do I have to recreate all records in the test method in order to use them?

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

Pascal T wrote:

Hello,

 

In my test method it looks like there is no pricebook record I can use.

The following code returns the value 0 while I have 4 Pricebook records in my sandbox.

 

System.debug('There is '+[SELECT COUNT() FROM Pricebook2]+ ' Pricebook(s)');

 

 

Do I have to recreate all records in the test method in order to use them?


You will need to use:

 

@isTest(SEEALLDATA = true)

 

 

All Answers

Starz26Starz26

Pascal T wrote:

Hello,

 

In my test method it looks like there is no pricebook record I can use.

The following code returns the value 0 while I have 4 Pricebook records in my sandbox.

 

System.debug('There is '+[SELECT COUNT() FROM Pricebook2]+ ' Pricebook(s)');

 

 

Do I have to recreate all records in the test method in order to use them?


You will need to use:

 

@isTest(SEEALLDATA = true)

 

 

This was selected as the best answer
Pascal TPascal T

Thank you