You need to sign in to do that
Don't have an account?
Behzad Bahadori 18
Method does not exist or incorrect signature: Test.getStandardPricebookId() API Version 31.0
I am writing a test class and I cant use Test.getStandardPricebookId() , and if I use @isTest (SeeAllData = true) Ill get the error that
STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []
Here is the test case
STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []
Here is the test case
Product2 prod = new Product2(Name = 'Laptop X200', Family = 'Hardware'); insert prod; // Get standard price book ID. // This is available irrespective of the state of SeeAllData. Id pricebookId = Test.getStandardPricebookId(); // 1. Insert a price book entry for the standard price book. // Standard price book entries require the standard price book ID we got earlier. PricebookEntry standardPrice = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true); insert standardPrice; // Create a custom price book Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true); insert customPB; // 2. Insert a price book entry with a custom price. PricebookEntry customPrice = new PricebookEntry( Pricebook2Id = customPB.Id, Product2Id = prod.Id, UnitPrice = 12000, IsActive = true); insert customPrice; QuoteLineItem qli = New QuoteLineItem(); qli.Product2Id=prod.id; qli.UnitPrice=12; qli.Quantity=50; qli.QuoteId=qot.id; qli.UnitPrice=50; qli.PricebookEntryId=customPrice.id; insert qli;
I thought with Summer '14 you should be able to use the Test.getStandardPricebookId() method but if that isn't working then you could set SeeAllData to true and then replace line 7 with the following:
Here are some additional resources that might prove useful:
https://developer.salesforce.com/forums/?id=906F00000008yveIAA
http://stackoverflow.com/questions/9164986/how-do-i-avoid-standard-price-not-defined-when-unit-testing-an-opportunitylineit
All Answers
I thought with Summer '14 you should be able to use the Test.getStandardPricebookId() method but if that isn't working then you could set SeeAllData to true and then replace line 7 with the following:
Here are some additional resources that might prove useful:
https://developer.salesforce.com/forums/?id=906F00000008yveIAA
http://stackoverflow.com/questions/9164986/how-do-i-avoid-standard-price-not-defined-when-unit-testing-an-opportunitylineit
thank you for the respond . yes I dont understand why its not working with my API ; now it says FIELD_INTEGRITY_EXCEPTION, The pricebook entry is in a different pricebook than the one assigned to the Quote, or Quote has no pricebook assigned
Try taking a look at this StackExchange post:
http://salesforce.stackexchange.com/questions/49426/pricebookentry-is-not-correctly-assigned