You need to sign in to do that
Don't have an account?

DUPLICATE_VALUE:The price definition already exist in the pricebook:[] error in test class
Hi All,
I am getting DUPLICATE_VALUE: the price definition already exist in the price book:[] error in test class. How do we resolve it?
I am getting above error when I use standard product Id in test class. Class is passing If I use custom pricebookId but failing while deploying.
Code:
Product2 pd = new Product2(Name='Product1',IsActive=true);
Insert pd;
Id standardPbId = Test.getStandardPricebookId();
PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPbId,IaActive=true,UseStandardPrice=false,Product2Id=pd.Id,UnitPrice=1200);
insert pbe; // this line is failing
If I use below custom price book Id Instead standardPbId then it is passing but failing while deploying it.
Pricebook2 customPb= new Pricebook2(Name='sample price book',IsActive=true);
insert customPb;
I tried below work arounds but didn't work.
Pricebook2 pb2 = new Pricebook2 (Id=Test.getStandardPricebookId(),IsActive=true);
update pb2;
Id standardPbId =[SELECT Id FROM Pricebook2 where IsStandard=true LIMIT 1].Id;
Did any one got this error and resolve it. please provide the solution for this.
I am getting DUPLICATE_VALUE: the price definition already exist in the price book:[] error in test class. How do we resolve it?
I am getting above error when I use standard product Id in test class. Class is passing If I use custom pricebookId but failing while deploying.
Code:
Product2 pd = new Product2(Name='Product1',IsActive=true);
Insert pd;
Id standardPbId = Test.getStandardPricebookId();
PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPbId,IaActive=true,UseStandardPrice=false,Product2Id=pd.Id,UnitPrice=1200);
insert pbe; // this line is failing
If I use below custom price book Id Instead standardPbId then it is passing but failing while deploying it.
Pricebook2 customPb= new Pricebook2(Name='sample price book',IsActive=true);
insert customPb;
I tried below work arounds but didn't work.
Pricebook2 pb2 = new Pricebook2 (Id=Test.getStandardPricebookId(),IsActive=true);
update pb2;
Id standardPbId =[SELECT Id FROM Pricebook2 where IsStandard=true LIMIT 1].Id;
Did any one got this error and resolve it. please provide the solution for this.
You don't have duplicate value on PriceBookEntry when deploying to Prod:
Similar kind of issue solution provided here.
https://developer.salesforce.com/forums/?id=9060G0000005k1QQAQ
If this information helps, Please mark it as best answer.
Thanks!!
All Answers
You don't have duplicate value on PriceBookEntry when deploying to Prod:
Similar kind of issue solution provided here.
https://developer.salesforce.com/forums/?id=9060G0000005k1QQAQ
If this information helps, Please mark it as best answer.
Thanks!!