+ Start a Discussion
azu.shaik1.3965080575576013E12azu.shaik1.3965080575576013E12 

Create the testclass for the wapper class

Hi Guys iam new to salesforce can some help me how to create the test class for the wapper calss

public with sharing class PlaceNeworders {

   


public String distributorId { get; set; }
public Order__c theOrder {get; set;}
public Order_Item__c theOrderItem {get; set;}
public List<wrapNewOrder> inventoryList { get; set; }
Public List<Inventory_Item__c> invItems {get;set;}
public Date dateName { get; set; }
public String selectedRestaurantId { get; set; }
public Boolean confirmNewOrderFlag {get; set;}


    public List<selectoption> getRestaurants1() {
        List<selectoption> Options = new List<selectoption>();
        Id accountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Restaurant / Buyer'].Id;
        List <Account> accounts = [Select Name, Id from Account where RecordTypeId = :accountRecordType ];
        for (Account a : accounts)
         options.add(new SelectOption(a.Id, a.Name));
         return Options;
    }
   
   /*  public List<selectoption> getDistributor() {
        List<selectoption> Dist = new List<selectoption>();
        Id accountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Distributor'].Id;
        List <Account> accounts = [Select Name, Id from Account where RecordTypeId = :accountRecordType ];
        Dist.add( new SelectOption('','Select'));
        for (Account a : accounts)
         Dist.add(new SelectOption(a.Id, a.Name));
         return Dist;
    
    }*/


   
     // Inserting the OrderItem into ordefullfilment Page and Navigating to OrderFullfilement page.
    public List<SelectOption> getUnitOrders() {
        List<SelectOption> options = new List<SelectOption>();
              
       Schema.DescribeFieldResult fieldResult =  Order_Item__c.Desired_Units__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       
        for( Schema.PicklistEntry f : ple)
        {
          options.add(new SelectOption(f.getLabel(), f.getValue()));
        }      
      
        
        return options;
    }    
   
    public void selectedDistributor() {
        User lgdUsr=[select id,name ,Distributor__c,profileId from User where id=:UserInfo.getUserId()];
      string profileName=[Select Id,Name from Profile where Id=: lgdUsr.profileId].Name;
      inventoryList = new List<wrapNewOrder> ();
   //  set<string>
      if(profileName == 'System Administrator'  ){
            system.debug('@@distributorId'+distributorId);
           
            invItems = [SELECT Id,Cut_and_Size__c,Fresh_Frozen__c,Quantity_Available__c,Species__c,Distributor_Name__c,Price_per_Unit__c,Units__c FROM Inventory_Item__c where Quantity_Available__c > 0 ];
            System.debug('Entered into as system Adminisator'+ invItems + 'assdddddd'+distributorId+'@@Distributor_Name__c'+invItems );
          
          }
      else{
             invItems = [SELECT Id,Cut_and_Size__c,Fresh_Frozen__c,Quantity_Available__c,Species__c,Price_per_Unit__c,Units__c FROM Inventory_Item__c where Distributor_Name__c =: lgdUsr.Distributor__c AND Quantity_Available__c > 0];
          }
    }
   
    // Constructor load the inventory Items to page based on the user profile
   
    Public PlaceNeworders(){
   
    theOrder =new Order__c();
    inventoryList = new List<wrapNewOrder> ();
   
      selectedDistributor();
     
      for(Inventory_Item__c a: invItems) {
                // As each Order is processed we create a new wrapAddOrder object and add it to the inventoryList
                inventoryList.add(new wrapNewOrder(a));
            }
            System.debug(' Print enter'+inventoryList);
   
   
    }





// Insert the order and order items

public PageReference confirmNewOrder() {

  
       if(theOrder.id==null) {
            theOrder.Buyer__c = selectedRestaurantId;
            theOrder.Requested_Delivery_Date__c = datename ;
            insert theOrder;
           
            system.debug('TheOrder inserted'+theOrder);
        }
                         
                         
         List<Order_Item__c> items = new List<Order_Item__c>();
         for(wrapNewOrder wno : inventoryList) {
         
         
                  
            if(wno.selected == true) {
               system.debug('Enter into selected '+wno.selected);
               confirmNewOrderFlag = true ;
               Order_Item__c oItem = new Order_Item__c();
               oItem.Amount_Ordered__c = wno.amount;
               oItem.Comments__c = wno.splInstructions;
               oItem.Desired_Units__c = wno.selectDesiredUnit;
               system.debug('@@oItem.Desired_Units__c'+oItem.Desired_Units__c);
               oItem.Order__c = theOrder.Id;
               oItem.Inventory__c = wno.invItem.Id;
                items.add(oItem);
             
              System.debug('Print Amount'+wno.amount);
              System.debug('Print SpL'+wno.splInstructions);
              System.debug('Print id'+theOrder.Id);
            }
             
        }
         system.debug('Enter confirmNewOrderFlag '+confirmNewOrderFlag);
        if(confirmNewOrderFlag == null){
       
              system.debug('Enter into Not selected loop '+confirmNewOrderFlag) ;
                ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please select atleast one item');
                ApexPages.addMessage(msg);
            }
       
        if(items.size()>0){
              
              system.debug('Enter into Not  loop ') ;
              if(theOrder.Requested_Delivery_Date__c == null){
              ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Enter Requested Delivery Date');
                ApexPages.addMessage(msg);
                }
                else{
              insert items;
              System.debug(' -------item----------- '+ items);
              PageReference orderPage = new PageReference('/apex/'+'/OrderFulfillment2?sfdc.tabName=01rF0000000VOWh');
              orderPage.setRedirect(false);
              return orderPage;
       }
       
    }
       return null;
    }

  public PageReference Cancel() {
     
     PageReference orderItemPage = new PageReference('/apex/'+'/OrderFulfillment2?sfdc.tabName=01rF0000000VOWh');
        orderItemPage.setRedirect(true);
        return orderItemPage;
    }

       // This is our wrapper/container class.
      
         public class wrapNewOrder {
         public Inventory_Item__c invItem {get; set;}
         public Boolean selected {get; set;}
         public String splInstructions { get; set; }
         public Decimal amount { get; set; }
         Public String selectDesiredUnit{get; set;}
       
       

        public wrapNewOrder(Inventory_Item__c a) {
            this.invItem = a;
            this.selectDesiredUnit=a.Units__c;
            this.selected = false;
        }
    }

}
Ramu_SFDCRamu_SFDC
The following posts might help

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000919gIAA