I am trying to create a test utility class which would allow creating pricebook entries for products. However when I call the following method from a test class and pass a list of products, it throws me an error at the highlighted.
public static list<PricebookEntry> createPriceBookEntries(Integer NumberOfRecords, list<product2> products) {
list<PricebookEntry> pbes=new list<PricebookEntry>();
list <PriceBook2> pb2list = new list<PriceBook2>();
//get standard pricebook
Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true limit 1];
// create a standard pricebook before creating custom ones
for(Integer i = 0; i<NumberOfRecords;i++){
PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = products.get(i).id, UnitPrice = ((Math.random() + 1)*100000).intValue(), IsActive = true, UseStandardPrice = false);
pbes.add(standardPrice);
}
//create a custom proce book
for (Integer i = 0; i<NumberOfRecords; i++){
pb2list.add(new Pricebook2 (name = 'Test Price book-001', Description = 'Test Custom Price Book', isactive = true));
}
insert pb2list;
// create a custom pbe
for(Integer i = 0; i<NumberOfRecords;i++){
pbes.add(new Pricebookentry(Pricebook2Id = pb2list.get(i).id, Product2Id = products.get(i).id, UnitPrice = ((Math.random() + 1)*1000000).intValue(), IsActive = true, CurrencyIsoCode = 'USD'));
}
insert pbes;
system.debug('print size'+pbes.size());
system.debug('print pbes'+pbes);
return pbes;
Can anyone help me understand what needs to be changed in the pricebookentry record to get rid of this?