You need to sign in to do that
Don't have an account?
syed akram
How to write test class for below code?
public without sharing class UpdateList {
list<order> selectorder;
String quoteId {set; get;}
String selectedOrderId {set; get;}
public List<Order> selectedOrders {set; get;}
public Boolean orderUpdated {set; get;}
public UpdateList(){
quoteId = ApexPages.currentPage().getParameters().get('quoteID');
orderUpdated = false;
}
public PageReference selectOrder(){
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
return null;
}
public list<Order> getorderslist()
{
List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
return allords;
}
//call this method to update order, and copy all quote line items from quote
public PageReference updateOrder(){
//get selected orderId from the list
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
//get quote line items using the quoteId
List<OrderItem> orderLines = new List<OrderItem>();
for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate,
Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
OrderItem oLine = new OrderItem();
oLine.OrderId = selectedOrderId;
oLine.PricebookEntryId = qLine.PricebookEntryId;
oLine.Quantity = qLine.Quantity;
oLine.UnitPrice = qLine.UnitPrice;
oLine.Description = qLine.Description;
oLine.ServiceDate = qLine.ServiceDate;
orderLines.add(oLine);
}
insert orderLines;
orderUpdated = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
return null;
}
}
list<order> selectorder;
String quoteId {set; get;}
String selectedOrderId {set; get;}
public List<Order> selectedOrders {set; get;}
public Boolean orderUpdated {set; get;}
public UpdateList(){
quoteId = ApexPages.currentPage().getParameters().get('quoteID');
orderUpdated = false;
}
public PageReference selectOrder(){
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
return null;
}
public list<Order> getorderslist()
{
List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
return allords;
}
//call this method to update order, and copy all quote line items from quote
public PageReference updateOrder(){
//get selected orderId from the list
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
//get quote line items using the quoteId
List<OrderItem> orderLines = new List<OrderItem>();
for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate,
Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
OrderItem oLine = new OrderItem();
oLine.OrderId = selectedOrderId;
oLine.PricebookEntryId = qLine.PricebookEntryId;
oLine.Quantity = qLine.Quantity;
oLine.UnitPrice = qLine.UnitPrice;
oLine.Description = qLine.Description;
oLine.ServiceDate = qLine.ServiceDate;
orderLines.add(oLine);
}
insert orderLines;
orderUpdated = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
return null;
}
}
After that, you will just have to create a normal test class, creating some data in your table and calling the methods to test.
Hoping this will help you...