You need to sign in to do that
Don't have an account?
case comments
List has no rows for assignment - Pricebook2
I'm trying to set up some test code to insert 200 products. When I run the test code, I get an error stating: List has no rows for assignment. This is occuring on the code for:
Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];
The weird thing is, I copied and pasted the exact same code to execute anonymous and it ran fine, but running it through test coverage errors out. Am I missing something here?
Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true];
The weird thing is, I copied and pasted the exact same code to execute anonymous and it ran fine, but running it through test coverage errors out. Am I missing something here?
@isTest public class AfterOppTriggerTest { static testMethod void OppTest(){ //create a list of products List<Product2> productstoinsert = new List <Product2>(); for(Integer x = 0; x < 200 ;x++){ Product2 newprod = new Product2(Name = 'newprod' + x, isactive = true); productstoinsert.add(newprod); } insert productstoinsert; //Select the pricebook Pricebook2 pbook = [Select id from Pricebook2 where isStandard = true]; system.debug(pbook); //create pricebook entries List<PriceBookEntry> pbinsert = new List<PriceBookEntry>(); for(Integer x=0; x < 200; x++){ PriceBookEntry pbentry = new PricebookEntry(Pricebook2ID = pbook.Id, Product2ID = productstoinsert[x].id, unitprice = 100, isactive = true, usestandardprice = false); pbinsert.add(pbentry); system.debug(pbentry); } insert pbinsert; } }
Use
method instead of below line
Because by query you cann't get the id.Salesforce 14 summar provide this new method.
IF it helps you than please mark it as a solution and ENJOY APEX
All Answers
Use
method instead of below line
Because by query you cann't get the id.Salesforce 14 summar provide this new method.
IF it helps you than please mark it as a solution and ENJOY APEX