You need to sign in to do that
Don't have an account?
Issue of "List index out of bounds: 0".
Hi,
I am trying to insert test data as shown below:
CODE:
----------
List <PriceBook2> pb2list = new List<PriceBook2>();
List <Product2> prodlist = new List<Product2>();
List <PriceBookEntry> pbelist = new List<PriceBookEntry>();
List <PriceBookEntry> stdPbelist = new List<PriceBookEntry>();
//get standard pricebook
List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
for (Integer j = 0; j<quantity; j++){
pb2list.add(new PriceBook2(Name = 'Test Price Book' +j, isActive = true));
}
insert pb2list;
for (Integer j = 0; j < quantity; j++) {
prodlist.add(new Product2(Name = 'Test Product' +j, productCode = 'ABC', isActive = true));
}
insert prodlist;
//before you create custom pricebooks, create standard ones
for (Integer j = 0; j < quantity; j++) {
stdPbelist.add(new PriceBookEntry(Pricebook2Id=standardPbList[0].id, Product2Id=prodlist.get(j).id, UnitPrice=99, isActive=true, UseStandardPrice=false));
}
insert stdPbelist;
for (Integer j = 0; j < quantity; j++) {
pbelist.add(new PriceBookEntry(Pricebook2Id=pb2list.get(j).id, Product2Id=prodlist.get(j).id, UnitPrice=99, isActive=true, UseStandardPrice=false));
}
insert pbelist;
return pbelist;
I am getting the issue of "List index out of bounds: 0" nearthe below peice of code:
" stdPbelist.add(new PriceBookEntry(Pricebook2Id=standardPbList[0].id, Product2Id=prodlist.get(j).id, UnitPrice=99, isActive=true, UseStandardPrice=false));"
. Please help me on this.
Thanks,
JBabu.
Hi JBabu....
Please make sure that You are getting the value in below code :-
List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
Thanks
SFDC_Evolve
All Answers
Hi JBabu....
Please make sure that You are getting the value in below code :-
List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
Thanks
SFDC_Evolve
One More thing . . If you are using Limit 1 ... .
It would suggest you .... Do Not take List List<Pricebook2> standardPbList
Hi,
I am getting a record from the query..
I got the issue. I have one record but the version of the record is different, so the data is not being used in the test class.
I need to create a standard record in to pricebook2