You need to sign in to do that
Don't have an account?
Sylvain@RibbonFish
Product with Pricebook2 with pricebookEntry
Hi,
This code was working previously since one month I can't run it:
Product2 pdt2 = new Product2(Name='Test',ProductCode = '222'); Product2 pdt3 = new Product2(Name='Test',ProductCode = '222'); insert pdt2; insert pdt3; Pricebook2 pBook = [Select Id, Name, IsActive From Pricebook2 where IsStandard = true LIMIT 1]; PricebookEntry pBookEntry = new PricebookEntry(UnitPrice=35,Pricebook2Id=pBook.Id,Product2Id=pdt2.Id,IsActive=true,UseStandardPrice=false); insert pBookEntry;
The error:
Products do not have a standard price.
Thanks
All Answers
You might have deactivated the standard price in Pricebook, that using the product.
I did check that I got only one PB where is corresponding to the Standard PB and is active.
If you have not any of your custom pricebooks created and products assigned to that pricebook, it will not show for you. check again or explain your requirement in detail.
My requirement is to create a PricebookEntry in my test unit with a product.
So that's what to code in my first code was doing but not anymore.
Thanks
Ok maybe I was not really clear sorry I was in rush.
So I do need to create a priceBookEntry with a product in a test method (test unit, test file).
You can see my first post which create a product then query the pricebook2 table and create a priceBookEntry object to be able to create a sale opportunity after.
I'm getting the following error:
"Products do not have a standard price."
So if someone can help me please.
Thanks
Hi,
The following the procedure to insert records to test. Try this way,
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.