You need to sign in to do that
Don't have an account?
yarram
Urgent-"For Loop" code coverage on Apex Test class
HI all,
how to do for loop code coverage? for bleow code............
public Incoice__c invoice;
public List<QuoteLineItem> QLItemsList;
public List<QuoteLineItem> getQLItems()
{
QLItemsList=[Select id,TotalPrice,Qty_Sent__c,Comments__c,Subtotal,Product2.Name,Product2.ProductCode,Product2.Id,Quote.Name,
Quote.Id,UnitPrice,Quantity,ListPrice,LineNumber,Description,Discount from QuoteLineItem where QuoteId=:currentQuoteID ];
return QLItemsList;
}
public PageReference onSave()
{
invoice =new Invoice__c();
invoice.Boxes_Shipped__c=boxesShipped;
invoice.CRF=custRefNo;
try{
insert invoice;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Check' + e.getMessage()));
return null;
}
for(QuoteLineItem qlItem:QLItemsList) { //from here not coverd
InvoiceLine_Items__c invLine=new InvoiceLine_Items__c();
invLine.Incoice__c=invoice.Id;
invLine.Description__c=qlItem.Product2.Name;
invLine.Product__c=qlItem.Product2.Id;
invLine.Product_Code__c=qlItem.Product2.ProductCode;
invLine.Qty_Ordered__c=qlItem.Quantity;
invLine.Qty_Sent__c=qlItem.Qty_Sent__c;
invLine.Unit_Price__c=qlItem.UnitPrice;
invLine.Comments__c=qlItem.Comments__c;
try{
Insert invLine;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Check' + e.getMessage()));
return null;
}
}//upto here not coverd
PageReference detailsPage=new PageReference('/apex/invoiceDetails?id='+newDelDktID);
detailsPage.setRedirect(true);
return detailsPage;
}
please help me on this .......this is Urgent
how to do for loop code coverage? for bleow code............
public Incoice__c invoice;
public List<QuoteLineItem> QLItemsList;
public List<QuoteLineItem> getQLItems()
{
QLItemsList=[Select id,TotalPrice,Qty_Sent__c,Comments__c,Subtotal,Product2.Name,Product2.ProductCode,Product2.Id,Quote.Name,
Quote.Id,UnitPrice,Quantity,ListPrice,LineNumber,Description,Discount from QuoteLineItem where QuoteId=:currentQuoteID ];
return QLItemsList;
}
public PageReference onSave()
{
invoice =new Invoice__c();
invoice.Boxes_Shipped__c=boxesShipped;
invoice.CRF=custRefNo;
try{
insert invoice;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Check' + e.getMessage()));
return null;
}
for(QuoteLineItem qlItem:QLItemsList) { //from here not coverd
InvoiceLine_Items__c invLine=new InvoiceLine_Items__c();
invLine.Incoice__c=invoice.Id;
invLine.Description__c=qlItem.Product2.Name;
invLine.Product__c=qlItem.Product2.Id;
invLine.Product_Code__c=qlItem.Product2.ProductCode;
invLine.Qty_Ordered__c=qlItem.Quantity;
invLine.Qty_Sent__c=qlItem.Qty_Sent__c;
invLine.Unit_Price__c=qlItem.UnitPrice;
invLine.Comments__c=qlItem.Comments__c;
try{
Insert invLine;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Check' + e.getMessage()));
return null;
}
}//upto here not coverd
PageReference detailsPage=new PageReference('/apex/invoiceDetails?id='+newDelDktID);
detailsPage.setRedirect(true);
return detailsPage;
}
please help me on this .......this is Urgent
The query for QLItemsList is returning nothing.
Also in the for loop there is an insert statement, it is not a good practice.
You might face governor limit issues.
for(QuoteLineItem qlItem:getQLItems())
In your class QLItemsList is fetched whose quote Id is currentQuoteID.
currentQuoteID is hardcoded (Ideally not to be done)
QuoteLineItem needs to be inserted with quoteID= currentQuoteID.