You need to sign in to do that
Don't have an account?
Waqas Ali
Unit test for opportunity Line Items
Here is my apex class copying the opportunity line items of current opportunity to newly created order and opportunity. I do not know how to write unit test for opportunity line items,
String theId = ApexPages.currentPage().getParameters().get('id'); List<OpportunityLineItem> currentOppLI = [ SELECT PricebookEntryId, Quantity, UnitPrice, TotalPrice, ListPrice, Description FROM OpportunityLineItem WHERE OpportunityId = :theId]; //Create the Order Order odr = new Order( OpportunityId=o.id ,AccountId = o.AccountId ,Name = o.Name ,EffectiveDate=Date.today() ,Status='Draft' ,Pricebook2Id = o.Pricebook2Id ); insert odr; //copy Opportunity line items to Order line items List<OrderItem> newOrderProductsList = new List<OrderItem>(); for (OpportunityLineItem item : currentOppLI) { newOrderProductsList.add(new OrderItem( PricebookEntryId = item.PricebookEntryId, Quantity = item.Quantity, UnitPrice = item.UnitPrice, Description = item.Description, OrderId = odr.Id)); } insert newOrderProductsList; List<OpportunityLineItem> newOppLI = new List<OpportunityLineItem>(); for (OpportunityLineItem item : currentOppLI) { newOppLI.add(new OpportunityLineItem( PricebookEntryId = item.PricebookEntryId, Quantity = item.Quantity, UnitPrice = item.UnitPrice, Description = item.Description, OpportunityId = opp.Id)); } insert newOppLI; //opp is newly created opportunity and odr is newly created orderHow to write unit test for opportunity line items and order items??
Please check below blog for more information on test classess
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Please try below code.
Please modify the code in Test.startTest(); and Test.stopTest(); according to your apex class. I added sample code for Controller and StandardController
Test Class for Controller class
Test Class for Standard Controller
Please let us know if this will help u
Thanks,
Amit Chaudhary
All Answers
Please check below blog for more information on test classess
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
Please try below code.
Please modify the code in Test.startTest(); and Test.stopTest(); according to your apex class. I added sample code for Controller and StandardController
Test Class for Controller class
Test Class for Standard Controller
Please let us know if this will help u
Thanks,
Amit Chaudhary
Amit Chaudhary you are great, you are life saviour man.
Thank You
-waqas