function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohan S 79Mohan S 79 

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.
Best Answer chosen by Mohan S 79
AnkaiahAnkaiah (Salesforce Developers) 
Hi Mohan,

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

AnkaiahAnkaiah (Salesforce Developers) 
Hi Mohan,

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!!
 
This was selected as the best answer
Rafsan KhanRafsan Khan
The best way to play online games is to set up an account. There are a number of websites that offer free online games. Creating an account is an essential step when you want to play games on the internet. This will allow you to browse through hundreds of millions of titles. Having a profile allows you to save your progress and save your game history. By doing this, you will be able to keep track of your progress and find a game that suits your preferences.You can go to download PK XD MOD APK (https://apkhustle.com/pk-xd-mod-apk-download-unlimited-money-and-gems/)
 
Big Baby Tape 7Big Baby Tape 7
Have you ever heard of cricket betting? An acquaintance told me about it six months ago, and I've been betting all this time. I can advise you on a website https://cricketbetting10.in/cricket-betting-apps/ where you'll find information about popular cricket betting apps, you'll find a lot of useful information. I think that's exactly what you need.