You need to sign in to do that
Don't have an account?
Jeff_Rogers.ax1383
SOQL Issue In Trigger Test Class
I'm trying to enter a new pricebookentry into the standard price book (which is inactive), but I can't get any results querying for the Standard Price Book (planning on setting inactive to false) through the test class. Here's the error I get:
System.QueryException: List has no rows for assignment to SObject
And here is the query:
PriceBook2 pbStd = [SELECT Id, IsActive FROM PriceBook2 WHERE Name = 'Standard Price Book'];
When I run the same query in the Force IDE I get the record.
Any thoughts?
Adding the annotation (seeAllData=true) to the end of @isTest AND activating/deactivating the Standard Price Book (weird) allowed me to get my test class to work as desired. Thanks for all the suggestions!
All Answers
Ensure you aren't running the test class query as a User who would not have permission to access those pricebook records.
Also, try the IsTest(SeeAllData=true) annotation for your test, if it's API version 25.0.
Thank you for the reply. I'm running the test under my account which has access to the standard price book. Also, I added the "SeeAllData" annotation and still did not get any results from the query. Are there no results because the standard price book is inactive? I wouldn't think that would be the case since I get results when I run the query through the Force IDE. Any other ideas?
Hi Jeff,
You should be able to query from the Pricebook even though it is inactive. I generally query the standard pricebook using the query below.
Hope it helps.
Thanks,
Jerun Jose
Adding the annotation (seeAllData=true) to the end of @isTest AND activating/deactivating the Standard Price Book (weird) allowed me to get my test class to work as desired. Thanks for all the suggestions!