You need to sign in to do that
Don't have an account?
Shuhbam Sinha
Getting error while creating pricebook entry
Hello,
I am trying to create price book entry through apex but I am getting this error USER_DEBUG|[56]|DEBUG| Before creating a custom price, create a standard price.
I am trying to create price book entry through apex but I am getting this error USER_DEBUG|[56]|DEBUG| Before creating a custom price, create a standard price.
for (Opportunity opp: [Select ID, Pricebook2ID FROM Opportunity WHERE ID = : oppId]){ priceBookId = String.isBlank(priceBookId) ? opp.Pricebook2ID : priceBookId; } if(lstPricebookEntry.size()== 0){ PricebookEntry pbe = new PricebookEntry(); pbe.Pricebook2Id = priceBookId; pbe.Product2Id = productId; // getting id from aura. pbe.UnitPrice = 10; pbe.UseStandardPrice=true; pbe.IsActive=true; pbeList.add(pbe); Database.SaveResult[] srPBEList = Database.insert(pbeList, false);Could anyone please help what I am missing here.
before adding product to custom PriceBook it must have Standard Price. In other words it must be added to Standard PriceBook.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
you need to assign standard price book to price book entry.
try with below.
Refer the below link.
https://salesforce.stackexchange.com/questions/232265/create-standard-price-book-programmatically
If this helps, Please mark it as best answer.
Thanks!!
I tried that as well but my opportunity falls on the custom price book and if i used this standard price book then I am getting
FIELD_INTEGRITY_EXCEPTION: unknown (pricebook entry is in a different pricebook than the one assigned to the opportunity . Do you have any alternative for this
Can you share the full code?
Thanks!!
before adding product to custom PriceBook it must have Standard Price. In other words it must be added to Standard PriceBook.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
pbe.UseStandardPrice=FALSE; not true