I'm coding a tringger which takes all the new products and inserts them automatically in the Org's pricebooks. Now: -newProd is a list of new Products -notStandardPB is the list of Org's pricebooks Below you find my code:
PricebookEntry notStandardPBE = new PricebookEntry();
for(Pricebook2 p:notStandardPB){
for(Product2 prodTopbb : newProd){
System.debug(prodTopbb.Id);
notStandardPBE.Pricebook2Id = p.Id;
notStandardPBE.Product2Id = prodTopbb.Id;
notStandardPBE.UseStandardPrice = true;
notStandardPBE.IsActive=true;
pbeNotStandardList.add(notStandardPBE);
}
}
System.debug('non standard pb: '+pbeNotStandardList);
System.debug('non standard pb: '+pbeNotStandardList.size());
insert pbeNotStandardList;
When trigger fires the System throws the error: "System.ListException: Before Insert or Upsert list must not have two identically equal elements". Infact seems like the trigger takes only the first product's Id and I don't understand why. Could someone help me please?