• Girbson Bijou 7
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 10
    Replies
Help me in increasing  the coverage of a class and writing  test class for a tiggger which refer a class.
The class is: 
public class DetailedDistributionTrigger
{
    public static void afterUpdateOperation(List<Container__c> lstNewContainers, Map<Id, Container__c> mapOldContainers)
    {
        List<String> lstUpdatedContainerIds = new List<String>();
        
        for(Container__c newContainer : lstNewContainers)
        {
            Container__c oldContainer = new Container__c();
            
            oldContainer = mapOldContainers.get(newContainer.Id);
            
            if(newContainer.Percent_Distributed__c == 100 && oldContainer.Percent_Distributed__c != 100)
            {
                lstUpdatedContainerIds.add(newContainer.Id);
            }
        }
        
        if(!lstUpdatedContainerIds.isEmpty())
            sendContainerPDF(String.join(lstUpdatedContainerIds,','));
    }
    
    @future(callout = true)
    public static void sendContainerPDF(String strUpdatedContainers)
    {
        List<String> lstContainerIds = new List<String>();
        lstContainerIds = strUpdatedContainers.split(',');
        
        List<Container__c> lstContainers = new List<Container__c>();
        
        if(!lstContainerIds.isEmpty())
        {
            lstContainers = [SELECT Id,Name, Owner.Email FROM Container__c WHERE Id IN :lstContainerIds];
        }
        
        for(Container__c Container :lstContainers)
        {
           // if(Container.Requisitor__c != null && Container.Requisitor__r.Contact_email__c != null)
           // {
            //    sendpdfEmail(Container,Container.Requisitor__r.Contact_email__c);
          //  }
            
          if(Container.Owner.Email != null)
           {
              sendpdfEmail(Container, Container.Owner.Email);
           }
        }  
    }
    
    public static void sendpdfEmail(Container__c Container, String emailid)
    {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 

        // Reference the attachment page and pass in the account ID
        PageReference pdf =  Page.Container_Report;
        pdf.getParameters().put('id',Container.Id); 
        pdf.setRedirect(true);
        Blob pdfData;
        
        // Take the PDF content
        if(!Test.isRunningTest())
        {
            pdfData = pdf.getContent();
        }
        else
        {
            pdfData = Blob.valueOf('test');
        }
        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(Container.Name + '.pdf');
        efa.setBody(pdfData);

        //String[] toAddresses = new List<String> {emailId};
        //email addresses to send email
          String[] toAddresses = new List<String>{'bijou.girbs@gmail.com'};

        // Sets the paramaters of the email
        email.setSubject(Container.Name +' Detailed Distribution Report');
        email.setToAddresses( toAddresses );
        email.setPlainTextBody('The Container ' + Container.Name +  ' has been totally distributed, Please find attached the detailed distribution report' );

        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

        // Sends the email
        Messaging.SendEmailResult [] r = 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }
}



The Test Class is:

@IsTest
private class DetailedDistributionTriggerTest{
static   TestMethod void  DetailedDistributionTrigger(){
Container__c cont = new Container__c ( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert cont;
    
     Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
    
                 
          ac.Product__c=p.ID;
          ac.Unit_Weight__c = 45; 
          ac.Unit_Cost__c = 87;
          ac.Container__c= cont.ID;
          ac.Number__c = 55;
          ac.UM__c ='UNIT(S)';    
          ac.Local_ID__c = 7888;
          ac.Comments__c = 'UNIT(S)';
          ac.Purpose__c='Consignment';
          ac.Condition__c= 'New';
           
           insert ac;
    Account acc = new Account(Name = 'TestACC', Representant__c='TestBene', Departement__c='Ouest', Address__c='102, Test');
    insert acc;
    
    Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = acc.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
    
    Item_Distributed__c itemDis = new Item_Distributed__c();
    itemDis.Quantity__c = 44;
    itemDis.Product__c = ac.Id;
    itemDis.Delivery__c =del.Id;
    
    insert itemDis;
    
    Test.setCurrentPageReference(new PageReference('Page.Container__Report')); 
    System.currentPageReference().getParameters().put('id', cont.ID);
    DetailedDistributionTrigger ddt = new DetailedDistributionTrigger();

}
}



The Trigger is :

trigger DetailedDistrib on Container__c (After Update)
{
    if(Trigger.isAfter && Trigger.isUpdate)
    {
        DetailedDistributionTrigger.afterUpdateOperation(Trigger.New, Trigger.oldMap);
    }
}

 
Hi All,
Help me the increase the coverage of this class. Actually itg is at 40%

The test class is:
@IsTest
public class ContainerReportTest{
static testMethod  void containerReportTest (){
   
    Container__c cont = new Container__c ( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert cont;
    
     Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
    
                 
          ac.Product__c=p.ID;
          ac.Unit_Weight__c = 45; 
          ac.Unit_Cost__c = 87;
          ac.Container__c= cont.ID;
          ac.Number__c = 55;
          ac.UM__c ='UNIT(S)';    
          ac.Local_ID__c = 7888;
          ac.Comments__c = 'UNIT(S)';
          ac.Purpose__c='Consignment';
          ac.Condition__c= 'New';
           
           insert ac;
    Account acc = new Account(Name = 'TestACC', Representant__c='TestBene', Departement__c='Ouest', Address__c='102, Test');
    insert acc;
    
    Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = acc.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
    
    Item_Distributed__c itemDis = new Item_Distributed__c();
    itemDis.Quantity__c = 44;
    itemDis.Product__c = ac.Id;
    itemDis.Delivery__c =del.Id;
    
    insert itemDis;
    
    ContainerReportController CRC = new ContainerReportController();
    
}

}


The Controller is:


public class ContainerReportController
{
    public Container__c container {get;set;}
    public Map<String,List<Item_Distributed__c>> itemDistributed{get;set;}
    String containerId;
    
    
          
    
     
    public ContainerReportController()
    {
        container = new Container__c();
        itemDistributed = new Map<String,List<Item_Distributed__c>>();
        
        try
        {
            containerId = ApexPages.currentPage().getParameters().get('id');
            
            container = [SELECT Id,Name,DR__c, PO__c,Arrived_Date__c, Invoice__c, Pkl__c, Description__c, Container__c.Provenance__c, Percent_Distributed__c, Bill_of_Lading__c, Size_in_feet__c, Seal_No__c, 
                         (SELECT Id,Name,Prod__c,Number__c,Number_Distributed__c,Available__c,UM__c, Pending__c, Percentagedistributed__c FROM Articles_Containers__r)
                         FROM Container__c WHERE Id =:containerId];
            
            if(container != null)
            {
                Set<Id> articleContainersId = new Set<Id>();
                
                if(!container.Articles_Containers__r.isEmpty())
                {
                    for(Articles_Containers__c art :container.Articles_Containers__r)
                    {
                        articleContainersId.add(art.Id);
                        itemDistributed.put(art.Id, new List<Item_Distributed__c>());
                    }
                }
                
                List<Item_Distributed__c> lstItemDistributed = new List<Item_Distributed__c>();
                
                lstItemDistributed = [SELECT Id, Name,Product__c,Quantity__c,Delivery__c,Productt__c, Beneficiary__c, Date__c   
                                      FROM Item_Distributed__c WHERE  Del_Status__c='Delivered'AND Product__c IN :articleContainersId];
                
                if(!lstItemDistributed.isEmpty())
                {
                    for(Item_Distributed__c item :lstItemDistributed)
                    {
                        if(itemDistributed.containsKey(item.Product__c))
                        {
                            itemDistributed.get(item.Product__c).add(item);
                        }
                    }
                }
            }         
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }
    }
}

 
What is the syntax to use Priorvalue of  field in parent record Validation Rule

ISPICKVAL( Delivery__r.Delivery_status__c , "Delivered")
the one below does not wok
ISPICKVAL( PRIORVALUE(Delivery__r.Delivery_status__c , "Delivered"))
 
HI Developers,
I need A trigger  to copy the value of a parent field to a child field. My parent object is Delivery__c, the child object is ItemDestributed__c
The parent child called Status__c and the child field called DelStatus__c. I need that these 2 field have same values all the time.
Hi all, I have a VF page rendered as PDF which display data from on object. I need to send this pdf as attachement to an email every week day.
Please explain me how to do it step by step.
The class is:
public class InventoryReport {

      public List<AggregateResult> allproduct{get;set;}

     public InventoryReport() {

   allproduct = [
      
      
      
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
      WHERE IsOpened__c = 1
GROUP BY Product_Hiden_Name__c , UM__c 
HAVING SUM(On_Hand__c) >0 
ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
                }
}

The page is

<apex:page controller="InventoryReport" renderAs="pdf" showHeader="false" sidebar="false"  standardStylesheets="false"    applyBodyTag="false" >

<head>
        <style type="text/css" media="print">
            tr {
            //font-family: Consolas, monaco, monospace;
           // font-weight:6px;
            font-size:12px;}
            @page {    
            @bottom-left {
            content: element(footer);
            size:letter;
       
            }
            }
            // .tablebody{
            // font-size=18px;
            // }
            
            /*   .sectionHeader {
            width: 100%;
            //background-color: #eee;
            
            font-size: 20pt;
            padding: 0px;
            margin: 15px 0px;
            font-weight: bold;
            }*/
            .head{
            width:65%;
            display: table;
            }
            .col {
            display:table-cell;
            line-height:1.1em;
            vertical-align: middle;
            }
            
            .logo{
            width: 30%;
            
            }
            .name{
            width: 70%;
            }
            .name h2, .name h6{
            margin: 0;
            padding: 0;
            margin-left: 10px;
            
            line-height: 1.1em;
            }
            
            .tableHeader {
            border-width: 0px 0px 0px 0px;
            border-color: #000;
            border-style: solid;
            }
            
            table {
            width: 100%;
            }
            .centered {
            text-align: center;
            }
            h3{  
            text-align: center;
            }
            
            .right {
            text-align: right;
            }
            
            .firstBlock
            {
            width: 90%; 
            margin-left: 20px;
            }
            
            
            .beneInfo{
            border-width: 1px 1px 1px 1px;
            border-style: solid;
            margin: 20px;
            
            
            }
            .SubfirstBlock{
            display:table-cell;
            width:800px;
            line-height: 1.5em;
            }
            .tableBeneinfo{
            display:table-cell;
            width:800px;
            line-height: 1.2em;
            
            }
            
            .tableBeneinfo div{
            border-top: 1px solid black;
            display: inline;
            margin-right:5px;
            width: 100px;
            text-align:center;
            }
            .footer {
            display: block;
            padding: 5px;
            position: running(footer);
            margin-bottom: 20px
            
            }
            
            .signature
            {margin-top:30px
           
            }
            
            .subfooter {
            display: inline-block;
            }
            
            .status{
            width: 30%;
            background-color: #eee;
            font-size: 12pt;
            padding: 5px;
            margin: 20px 0px;
            font-weight: bold;
            }
            
            
            
            div.right {
            float: right;
            }
            
            .pagenumber:before {
            content: counter(page);
            }
            
            .pagecount:before {
            content: counter(pages);
            }
        </style>
    </head>
    <div class="head">        
        <div class="col logo">
            <apex:image url="{!$Resource.LogoFFP}" width="140" height="60"/>
        </div>
        <div class ="col name"> 
            <h2>
                FOOD FOR THE POOR
            </h2>           
            <h6>
                14, Mapou Rte. Nationale #1
                Cap Haitien, Haiti. Tels:(+509)2208-9960/3409-5328
            </h6>
        </div>        
    </div>
            <br/>
                           
    <h3> INVENTORY STOCK STATUS REPORT  UPDATED ON:<apex:outputtext value="{0, date, Long}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext> <br/></h3>
            <br/>
         
   <div class="table">
        
        <div class="tableHeader">       
            <th>ITEM</th> 
            <th>UNIT OF MEASURE </th> 
            <th>ON HAND </th> 
            <th>PENDING </th> 
            <th>AVAILABLE </th>
            
        </div>

        <apex:repeat value="{!allproduct}" var="a"> 
         <!--  <div class="tablebody"> -->
               
  <tr>
     
     <td>{!a['Product_Hiden_Name__c'] }</td>
     <td>{!a['UM__c']}</td>
     <td>{!a['OnHand']}</td> 
     <td>{!a['Pending']}</td>
     <td>{!a['avail']}</td>
  </tr> 
           
        </apex:repeat>
    
     </div>
    
     <div class="footer">
        <div>
           
            Printed by :  {!$User.FirstName} {!$User.LastName} <apex:outputtext value="{0, date, long}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext> <br/>
            As often as you did it for one of my  least brothers, you did it for me. Matthiew 25:40 <br/>
              </div>
    </div>   
    
</apex:page>
Why the coverage is 0% while the test passed?
Here is my class

public class InventoryReport {

      public List<AggregateResult> allproduct{get;set;}

     public InventoryReport() {

   allproduct = [      
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
      WHERE IsOpened__c = 1
      GROUP BY Product_Hiden_Name__c , UM__c 
      HAVING SUM(On_Hand__c) >0 
      ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
      }
}

The test is:

@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
          ac.Product__c=p.ID;
           ac.Unit_Weight__c = 45; 
           ac.Unit_Cost__c = 87;
            ac.Container__c= c.ID;
             ac.Number__c = 55;
            ac.UM__c ='UNIT(S)';    
           ac.Local_ID__c = 7888;
           ac.Comments__c = 'UNIT(S)';
           ac.Purpose__c='Consignment';
           ac.Condition__c= 'New';
           insert ac;   
}
}
 
In get the following message in the inbound change set.  Help me please
nventoryReportTest    TestInventoryReport    System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Container__c]: [Container__c]  Stack Trace: Class.InventoryReportTest.TestInventoryReport: line 20, column 1

My class is:


public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 

public void search(){ 
string searchquery= 'select Name , Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  Limit 50000';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 

}

The test class is:

@isTest (SeeAllData=true)
public class InventorySearchTest {
    static testMethod void testMethod1(){
      
          Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          ac.Product__c=p.ID;
           ac.Unit_Weight__c = 45; 
           ac.Unit_Cost__c = 87;
            ac.Container__c= c.ID;
             ac.Number__c = 54;
            ac.UM__c ='UNIT(S)';    
           ac.Local_ID__c = 7888;
           ac.Comments__c = 'UNIT(S)';
           ac.Purpose__c='Consignment';
           ac.Condition__c= 'New';
           insert c;
           insert p;
           insert ac;
           
           
           InventorySearchController Inv = new  InventorySearchController();
             Inv.searchstring = 'testFullName';
             Inv.search();
             Inv.clear();
            
        }
}
 
Help please,  
 The erro message is List has more than 1 row for assignment to SObject error
I test the SOQL query in developer Console, and work as expected But, i get error message  in the VF

My Controller is: 

public class InventoryReport {

     public List<Articles_Containers__c> allproduct{get;set;}

     public InventoryReport() {

    AggregateResult allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

VF Page is:

<apex:page controller="InventoryReport" showHeader="true" RenderAs="PDF">
<div class="table">
       <div class="tableHeader">
              <th>Item</th>
              <th>Unit Of Measure </th>
              <th>On Hand </th>
              <th>Pendig </th>
              <th>Available </th>
      </div>
<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a.Product_Hiden_Name__c }</td>
    <td>{!a.UM__c}</td>
    <td>{!a['onHand']}</td>  
    <td>{!a.['Pending']}</td>
    <td>{!a.['avail']}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
New in testing, I need  the test class for this below trigger

trigger ItemToDelete on Delivery__c(after update) {
 
 Set<Id> setDeliveryIds = new Set<Id>();
 
 for (Delivery__c delivery : trigger.new) {
  if (delivery.Delivery_status__c == 'Voided') {
   setDeliveryIds.add(delivery.Id);
  }
 }
 
 if(!setDeliveryIds.isEmpty())
 {
  List<Item_Distributed__c> itemsToDelete = [SELECT id FROM Item_Distributed__c WHERE Delivery__c IN :setDeliveryIds];
  
  if(!itemsToDelete.isEmpty())
   DELETE itemsToDelete;
 }
}
Help please, I test the SOQL query in developer Console, and work as expected But, i get error message  in the VF

My Controller is: 

public class InventoryReport {

     public List<Articles_Containers__c> allproduct{get;set;}

     public InventoryReport() {

    AggregateResult allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

VF Page is:

<apex:page controller="InventoryReport" showHeader="true" RenderAs="PDF">
<div class="table">
       <div class="tableHeader">
              <th>Item</th>
              <th>Unit Of Measure </th>
              <th>On Hand </th>
              <th>Pendig </th>
              <th>Available </th>
      </div>
<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a.Product_Hiden_Name__c }</td>
    <td>{!a.UM__c}</td>
    <td>{!a.On_Hand__c}</td>
    <td>{!a.Pending__c}</td>
    <td>{!a.Available__c}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
Helpo to create the Test class for this Controller please

public with sharing class InventorySearch { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearch( ) { 

public void search(){ 
string searchquery= 'select  Item_Full_Name__c,  UM__c,   On_Hand__c,  Pending__c,  Available__c FROM Articles_Containers__c  WHERE Item_Full_Name__c like \'%'+searchstring+'%\' AND On_Hand__c >0  Limit 20';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 

}
Hi All,
Help me the increase the coverage of this class. Actually itg is at 40%

The test class is:
@IsTest
public class ContainerReportTest{
static testMethod  void containerReportTest (){
   
    Container__c cont = new Container__c ( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert cont;
    
     Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
    
                 
          ac.Product__c=p.ID;
          ac.Unit_Weight__c = 45; 
          ac.Unit_Cost__c = 87;
          ac.Container__c= cont.ID;
          ac.Number__c = 55;
          ac.UM__c ='UNIT(S)';    
          ac.Local_ID__c = 7888;
          ac.Comments__c = 'UNIT(S)';
          ac.Purpose__c='Consignment';
          ac.Condition__c= 'New';
           
           insert ac;
    Account acc = new Account(Name = 'TestACC', Representant__c='TestBene', Departement__c='Ouest', Address__c='102, Test');
    insert acc;
    
    Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = acc.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
    
    Item_Distributed__c itemDis = new Item_Distributed__c();
    itemDis.Quantity__c = 44;
    itemDis.Product__c = ac.Id;
    itemDis.Delivery__c =del.Id;
    
    insert itemDis;
    
    ContainerReportController CRC = new ContainerReportController();
    
}

}


The Controller is:


public class ContainerReportController
{
    public Container__c container {get;set;}
    public Map<String,List<Item_Distributed__c>> itemDistributed{get;set;}
    String containerId;
    
    
          
    
     
    public ContainerReportController()
    {
        container = new Container__c();
        itemDistributed = new Map<String,List<Item_Distributed__c>>();
        
        try
        {
            containerId = ApexPages.currentPage().getParameters().get('id');
            
            container = [SELECT Id,Name,DR__c, PO__c,Arrived_Date__c, Invoice__c, Pkl__c, Description__c, Container__c.Provenance__c, Percent_Distributed__c, Bill_of_Lading__c, Size_in_feet__c, Seal_No__c, 
                         (SELECT Id,Name,Prod__c,Number__c,Number_Distributed__c,Available__c,UM__c, Pending__c, Percentagedistributed__c FROM Articles_Containers__r)
                         FROM Container__c WHERE Id =:containerId];
            
            if(container != null)
            {
                Set<Id> articleContainersId = new Set<Id>();
                
                if(!container.Articles_Containers__r.isEmpty())
                {
                    for(Articles_Containers__c art :container.Articles_Containers__r)
                    {
                        articleContainersId.add(art.Id);
                        itemDistributed.put(art.Id, new List<Item_Distributed__c>());
                    }
                }
                
                List<Item_Distributed__c> lstItemDistributed = new List<Item_Distributed__c>();
                
                lstItemDistributed = [SELECT Id, Name,Product__c,Quantity__c,Delivery__c,Productt__c, Beneficiary__c, Date__c   
                                      FROM Item_Distributed__c WHERE  Del_Status__c='Delivered'AND Product__c IN :articleContainersId];
                
                if(!lstItemDistributed.isEmpty())
                {
                    for(Item_Distributed__c item :lstItemDistributed)
                    {
                        if(itemDistributed.containsKey(item.Product__c))
                        {
                            itemDistributed.get(item.Product__c).add(item);
                        }
                    }
                }
            }         
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }
    }
}

 
Hi All,
Help me the increase the coverage of this class. Actually itg is at 40%

The test class is:
@IsTest
public class ContainerReportTest{
static testMethod  void containerReportTest (){
   
    Container__c cont = new Container__c ( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert cont;
    
     Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
    
                 
          ac.Product__c=p.ID;
          ac.Unit_Weight__c = 45; 
          ac.Unit_Cost__c = 87;
          ac.Container__c= cont.ID;
          ac.Number__c = 55;
          ac.UM__c ='UNIT(S)';    
          ac.Local_ID__c = 7888;
          ac.Comments__c = 'UNIT(S)';
          ac.Purpose__c='Consignment';
          ac.Condition__c= 'New';
           
           insert ac;
    Account acc = new Account(Name = 'TestACC', Representant__c='TestBene', Departement__c='Ouest', Address__c='102, Test');
    insert acc;
    
    Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = acc.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
    
    Item_Distributed__c itemDis = new Item_Distributed__c();
    itemDis.Quantity__c = 44;
    itemDis.Product__c = ac.Id;
    itemDis.Delivery__c =del.Id;
    
    insert itemDis;
    
    ContainerReportController CRC = new ContainerReportController();
    
}

}


The Controller is:


public class ContainerReportController
{
    public Container__c container {get;set;}
    public Map<String,List<Item_Distributed__c>> itemDistributed{get;set;}
    String containerId;
    
    
          
    
     
    public ContainerReportController()
    {
        container = new Container__c();
        itemDistributed = new Map<String,List<Item_Distributed__c>>();
        
        try
        {
            containerId = ApexPages.currentPage().getParameters().get('id');
            
            container = [SELECT Id,Name,DR__c, PO__c,Arrived_Date__c, Invoice__c, Pkl__c, Description__c, Container__c.Provenance__c, Percent_Distributed__c, Bill_of_Lading__c, Size_in_feet__c, Seal_No__c, 
                         (SELECT Id,Name,Prod__c,Number__c,Number_Distributed__c,Available__c,UM__c, Pending__c, Percentagedistributed__c FROM Articles_Containers__r)
                         FROM Container__c WHERE Id =:containerId];
            
            if(container != null)
            {
                Set<Id> articleContainersId = new Set<Id>();
                
                if(!container.Articles_Containers__r.isEmpty())
                {
                    for(Articles_Containers__c art :container.Articles_Containers__r)
                    {
                        articleContainersId.add(art.Id);
                        itemDistributed.put(art.Id, new List<Item_Distributed__c>());
                    }
                }
                
                List<Item_Distributed__c> lstItemDistributed = new List<Item_Distributed__c>();
                
                lstItemDistributed = [SELECT Id, Name,Product__c,Quantity__c,Delivery__c,Productt__c, Beneficiary__c, Date__c   
                                      FROM Item_Distributed__c WHERE  Del_Status__c='Delivered'AND Product__c IN :articleContainersId];
                
                if(!lstItemDistributed.isEmpty())
                {
                    for(Item_Distributed__c item :lstItemDistributed)
                    {
                        if(itemDistributed.containsKey(item.Product__c))
                        {
                            itemDistributed.get(item.Product__c).add(item);
                        }
                    }
                }
            }         
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }
    }
}

 
HI Developers,
I need A trigger  to copy the value of a parent field to a child field. My parent object is Delivery__c, the child object is ItemDestributed__c
The parent child called Status__c and the child field called DelStatus__c. I need that these 2 field have same values all the time.
Why the coverage is 0% while the test passed?
Here is my class

public class InventoryReport {

      public List<AggregateResult> allproduct{get;set;}

     public InventoryReport() {

   allproduct = [      
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
      WHERE IsOpened__c = 1
      GROUP BY Product_Hiden_Name__c , UM__c 
      HAVING SUM(On_Hand__c) >0 
      ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
      }
}

The test is:

@Istest(SeeAllData=true)
public class InventoryReportTest{
static testMethod void TestInventoryReport(){
 Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
          insert c;
          
          ac.Product__c=p.ID;
           ac.Unit_Weight__c = 45; 
           ac.Unit_Cost__c = 87;
            ac.Container__c= c.ID;
             ac.Number__c = 55;
            ac.UM__c ='UNIT(S)';    
           ac.Local_ID__c = 7888;
           ac.Comments__c = 'UNIT(S)';
           ac.Purpose__c='Consignment';
           ac.Condition__c= 'New';
           insert ac;   
}
}
 
Help please,  
 The erro message is List has more than 1 row for assignment to SObject error
I test the SOQL query in developer Console, and work as expected But, i get error message  in the VF

My Controller is: 

public class InventoryReport {

     public List<Articles_Containers__c> allproduct{get;set;}

     public InventoryReport() {

    AggregateResult allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

VF Page is:

<apex:page controller="InventoryReport" showHeader="true" RenderAs="PDF">
<div class="table">
       <div class="tableHeader">
              <th>Item</th>
              <th>Unit Of Measure </th>
              <th>On Hand </th>
              <th>Pendig </th>
              <th>Available </th>
      </div>
<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a.Product_Hiden_Name__c }</td>
    <td>{!a.UM__c}</td>
    <td>{!a['onHand']}</td>  
    <td>{!a.['Pending']}</td>
    <td>{!a.['avail']}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
Help please, I test the SOQL query in developer Console, and work as expected But, i get error message  in the VF

My Controller is: 

public class InventoryReport {

     public List<Articles_Containers__c> allproduct{get;set;}

     public InventoryReport() {

    AggregateResult allproduct = [
      SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
         GROUP BY Product_Hiden_Name__c , UM__c 
         HAVING SUM(On_Hand__c)>0
          ORDER BY Product_Hiden_Name__c, UM__c
      limit 1000];

      }

}

VF Page is:

<apex:page controller="InventoryReport" showHeader="true" RenderAs="PDF">
<div class="table">
       <div class="tableHeader">
              <th>Item</th>
              <th>Unit Of Measure </th>
              <th>On Hand </th>
              <th>Pendig </th>
              <th>Available </th>
      </div>
<apex:repeat value="{!allproduct}" var="a"> <!-- <div class="tablebody"> -->
<tr>
   <td>{!a.Product_Hiden_Name__c }</td>
    <td>{!a.UM__c}</td>
    <td>{!a.On_Hand__c}</td>
    <td>{!a.Pending__c}</td>
    <td>{!a.Available__c}</td>
</tr>
  </apex:repeat> </div>
</apex:page>
Helpo to create the Test class for this Controller please

public with sharing class InventorySearch { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearch( ) { 

public void search(){ 
string searchquery= 'select  Item_Full_Name__c,  UM__c,   On_Hand__c,  Pending__c,  Available__c FROM Articles_Containers__c  WHERE Item_Full_Name__c like \'%'+searchstring+'%\' AND On_Hand__c >0  Limit 20';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 

}