1

Following is my apex class....The lines not covered are => marked

 public class OrderTrackingClass{ 

public class Order {
    public Orders__c sob {get; set;}
    public OrderLine[] orderLines {get; set;} 
    public InvoiceLine[] invoiceLines {get; set;} 
    Order(Orders__c sob) {
        this.sob = sob;
        this.orderLines = new OrderLine[] {};
        this.invoiceLines = new InvoiceLine[] {};
    }
}

public class OrderLine {
    public Order_Lines__c sob {get; set;}
    public ShipmentLine[] shipmentLines {get; set;}
    OrderLine(Order_Lines__c sob) {
        this.sob = sob;
        this.shipmentLines = new ShipmentLine[] {};
    }
}

public class ShipmentLine {
 =>   public Shipment_Lines__c sob {get; set;}
 =>   ShipmentLine(Shipment_Lines__c sob) {
 =>       this.sob = sob;
    }
}

public class InvoiceLine{
  =>  public invoice_lines__c sob {get; set;}

  =>  InvoiceLine(invoice_lines__c sob) {
 =>    this.sob = sob;

    }
}
// Visualforce gets all data starting from here
 public Order[] orders {get; set;}

 public OrderTrackingClass() {
  init();
 }

 public void init() {

    orders = new Order[] {};

    Map<Id, Order> ordersMap = new Map<Id, Order>();
    for (Orders__c sob : [
            select id, name, number_of_line_items__c,Orders__c, customer_order_number__c, account__r.name,CreatedDate  
            from Orders__c
            where Id = :ApexPages.currentPage().getParameters().get('id')

            ]) {
        Order w = new Order(sob);
        ordersMap.put(sob.Id, w);
        orders.add(w);
    }

    Map<Id, OrderLine> orderLinesMap = new Map<Id, OrderLine>();
    for (Order_Lines__c sob : [
            select id,name, number_of_order_lines__c
            from Order_Lines__c
            where number_of_order_lines__c in :ordersMap.keySet()

            ]) 

            {
            system.debug('sob----->'+sob);
        OrderLine w = new OrderLine(sob);
        orderLinesMap.put(sob.Id, w);
        // Add child to correct parent
        ordersMap.get(sob.number_of_order_lines__c).orderLines.add(w);
        system.debug('sob2----->'+sob);
        system.debug('ordersMap----->'+ordersMap);
    }

    Map<Id, ShipmentLine> shipmentLinesMap = new Map<Id, ShipmentLine>();
    for (Shipment_Lines__c sob : [
            select id,name, order_lines__c
            from Shipment_Lines__c
            where order_lines__c in :orderLinesMap.keySet()

            ]) {
 =>         ShipmentLine w = new ShipmentLine(sob);
  =>      shipmentLinesMap.put(sob.Id, w);
        // Add child to correct parent

  =>        orderLinesMap.get(sob.order_lines__c).shipmentLines.add(w); 
    }

            Map<Id, InvoiceLine> invoiceLinesMap = new Map<Id, InvoiceLine>();
       for (invoice_Lines__c sob : [
            select invoices__r.invoice_no__c
            from invoice_Lines__c
            where orders__c in :ordersMap.keySet()

            ]) 

            {
            system.debug('sob----->'+sob);
  =>          InvoiceLine w = new InvoiceLine(sob);
  =>           InvoiceLinesMap.put(sob.Id, w);
        // Add child to correct parent
  =>           ordersMap.get(sob.orders__c).InvoiceLines.add(w);

      }
     }

    }

Following is my Test class

    @isTest
  public class OrderTrackingClass_TEST
    {  
          static testMethod void coverCode(){
          Test.startTest();

          OrderTrackingClass controller = new OrderTrackingClass(); 
          controller.init();                


          Account acc = new Account(Name='ABC Corp.');
          insert acc;

          orders__c tempOrder = new orders__c(name = '0001234567', account__c = acc.id );
          insert tempOrder;

          order_lines__c tempOL1 = new order_lines__c();

          tempOL1.Name = '10';
         // tempOL1.order_number__c= tempOrder.id;
          tempOL1.number_of_order_lines__c=tempOrder.id;
          tempOL1.status__c = 'Open';
          tempOL1.calculated_estimated_delivery_date__c = date.today();// fot invoiced
          tempOL1.planned_ship_date__c = date.today();
          insert tempOL1;

          shipment_lines__c tempSL = new shipment_lines__c();
          tempSL.order_lines__c = tempOrder.id;
          tempSL.Name = '100';  

          //tempSL.CurrencyIsoCode = 'USD';               
          tempSL.estimated_delivery_date__c = date.today(); 

           invoice_lines__c tempIL1 = new invoice_lines__c(name = '0001234567', orders__c = tempOrder.id);


          PageReference pageRef = Page.OrderTrackingClass;
          Test.setCurrentPage(pageRef);
          ApexPages.Standardcontroller sc = new ApexPages.Standardcontroller(tempOrder);
          ApexPages.currentPage().getParameters().put('Id',tempOrder.id);

          Test.stopTest();

    }
 }

Please guide me. It seems I'm not covering the shipment and invoice lines . What am I missing?

3

Your test is not inserting the Shipment_lines__c and Invoice_lines__c records. See the two insert lines below, which you are not doing in your code

shipment_lines__c tempSL = new shipment_lines__c();
...
insert tempSL; // This line is missing
...
invoice_lines__c tempIL1 = new invoice_lines__c(name = '0001234567', orders__c = tempOrder.id);
insert tempIL1; // This line is missing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.