You need to sign in to do that
Don't have an account?
YongChen
SOQL in Apex test class
Hi,
The following code gives me different results when run it in test class.
When include this in test class, it gives me: "standardPB = 0" where in Execute Anonymous, it gives me "standardPB = 1".
I have the following code in my trigger, which gives me "List index out of bounds" when running test class.
Thanks,
The following code gives me different results when run it in test class.
Pricebook2[] standardPB = [Select Id From Pricebook2 where IsStandard = true]; System.debug('standardPB = '+standardPB.size());
When include this in test class, it gives me: "standardPB = 0" where in Execute Anonymous, it gives me "standardPB = 1".
I have the following code in my trigger, which gives me "List index out of bounds" when running test class.
String standardPBId = [Select Id From Pricebook2 where IsStandard = true][0].Id;Could someone explain it?
Thanks,
You have to use seeAllData= true in your test class.
Thanks
Shaijan Thomas
All Answers
To get the standard pricebook Id in your test class use the below code, which will get the without using seeAllData=true in your test class. To know more about pricebook entry check this link - http://docs.releasenotes.salesforce.com/en-us/summer14/release-notes/rn_apex_price_books_in_tests.htm
Hi Karanraj,
Thanks,Thank you for the reply.
"Test.getStandardPricebookId()" works great in test class, but the problem is, the following code in my trigger class (not my test class) throws "List index out of bounds" WHEN running test calss.
You have to use seeAllData= true in your test class.
Thanks
Shaijan Thomas