+ Start a Discussion

PriceBook query not working in API Version 24



I was writing a test class and in my test class I was querying Standard Pricebook


//Query Standard Price Book
 Pricebook2 pricebookObj = [select id from Pricebook2 where IsStandard = true];


This query works fine with API V-23. When we change the API version to 24 it gives System.QueryException - List has no rows for assignment to SObject.


Just gone through "Whats New" article for API version 24. But not found anything. Does anybody know what exactly the issue is?


You may want to check Spring '12 release notes.


Isolation of Test Data in Unit Tests
Starting with Salesforce API version 24.0, test methods don’t have access to pre-existing data in the organization, such as
standard objects, custom objects, and custom settings data. They can only access data that they create. This lets you to write
more robust unit tests by preventing any dependencies of tests on any existing data in the organization. By having every test
create and access its own data, no test will fail because the data it depends on doesn’t exist in the organization when the package
is being deployed.


You can choose to open up access of a test class or a test method to enable access to all data in the organization by using the
IsTest(SeeAllData=true) annotation. See New IsTest(SeeAllData=true) Annotation.