function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sandeepathadusandeepathadu 

hi plz help with test case

public class addpro1
{
 public List<OpportunitylineItem> Oppline  {get; set;}
  
  public Opportunity userip {get; set;} 
  
  public Opportunity Opadd ;
public OpportunitylineItem[] Oliadd ;
public Opportunity  bil;
public string id;

  public addpro1(ApexPages.StandardController controller)
   {
this.id =ApexPages.currentPage().getParameters().get('id');

system.debug('id'+this.id);
opadd =[select id,name,Total_Invoiced__c,Total_Approved__c ,StageFilter__c,final_stage__c ,Quote_vs_Billings_Difference__c ,Filterstage__c,Total_Planned__c,Total_Submitted__c,ownerid,Purchase_order__c,Account.name,stagename,CloseDate,amount,probability,Header_Opportunity__c,Accountid,Opp_Line_Items_Count__c,Billing_Contact__c,No_Of_Months_for_Billing__c from Opportunity where id=:id];
system.debug('id'+opadd.id);
bil=[select id, name,oppcheckbox__c  from opportunity where id=:opadd.Header_opportunity__c];
oliadd = [select id,Quantity,delete__c ,description,pricebookentry.name,UnitPrice,TotalPrice ,Foraddingproduct__c,Opportunityid,Quote_Original_List_Price__c,Product_Code__c   from OpportunityLineItem where opportunityid=:bil.id];
//oliadd = [select id,Quantity,delete__c ,description,pricebookentry.name,UnitPrice,TotalPrice ,Foraddingproduct__c,Opportunityid,Quote_Original_List_Price__c,Product_Code__c   from OpportunityLineItem where opportunityid=:id];
     Oppline = new List<OpportunitylineItem>();
       
  userip = new Opportunity();
   }
 
 public PageReference Ad() 

{
//for(Opportunity opadd1:opadd)
//{

  for(Opportunitylineitem oli1 :oliadd)
  {
        if( oli1.Foraddingproduct__c == true)
        {
        OpportunityLineItem olt = new OpportunityLineItem(); 
        olt.opportunityid =opadd.id; 
        olt.PricebookEntryId=oli1.PricebookEntryId; 
        
        olt.Product_Code__c =oli1.PricebookEntry.name;
        olt.quantity =oli1.Quantity;
        olt.unitprice = oli1.UnitPrice;
        olt.description=oli1.description;     
        Oppline.add(olt);
      
        }
     }  
  
//}
 insert  Oppline; 
 
   PageReference customPage = new PageReference('/apex/opptctldelete'); 
 
   customPage.getParameters().put('id', bil.id);
   customPage.setRedirect(true);
   return customPage; 
  
          

}
public PageReference cancelgoback() 

{

   PageReference customPage = new PageReference('/apex/opptctldelete'); 
 
   customPage.getParameters().put('id', bil.id);
   customPage.setRedirect(true);
   return customPage; 
  
          

}


public OpportunitylineItem[] getoliadd()
{
return oliadd;
}


}

 

Shashikant SharmaShashikant Sharma

You can see this I have provided a structure of a test class, this case suits to your, so jsut follw the steps and create test class.

http://forceschool.blogspot.com/search/label/Test%20Apex

 

If any issue please ask.