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
Suraj DemgundeSuraj Demgunde 

can some one help me in below test class its cover 69% only

trigger contupdate on Container__c (before update) {
    try{
    list<string> FPOName = new list<string>();
    String fnames='';
 
    for(Container__c currentCont : trigger.new){
  
        list<ICCWorkbench__c> getRelatedFPO = [Select Id,Name,Container_Name__r.Name,Bill_Lading__r.ZAC_PO__c  from ICCWorkbench__c where Container_Name__r.Name = : currentCont.Name];
        for(ICCWorkbench__c IccWb : getRelatedFPO){
    
            FPOName.add(IccWb.Name);
            fnames=fnames+IccWb.Name+',';
    
        }
            currentCont.ZAC_Purchase_order_Number__c =  String.join(FPOName,',');
         // currentCont.BOL_ID__r.ZAC_PO__c = currentCont.ZAC_Purchase_order_Number__c ;
 
            
            system.debug('FPOName-->'+ FPOName);
        
        Bill_Of_Lading__c bolObj=[Select Id,Name,ZAC_PO__c from Bill_Of_Lading__c where id = : currentCont.BOL_ID__c ];
        bolObj.ZAC_PO__c=fnames;
        update bolObj;
        
    }
    }
    
        catch(exception e){
            system.debug('Exception throw ->' + e.getMessage());
            
        }
  

}

test class

@isTest(SeeAlldata=true)
public class testcontainerupdate {
    testmethod static void  testfn(){
    Bill_Of_Lading__c bol = new Bill_Of_Lading__c();
   bol.CurrencyIsoCode ='EUR';
    bol.Name='kekekek';
    bol.ZAC_PO__c='testing,myfpo';
        bol.ZAC_PO__c = 'test,test2';
    insert bol;
        
        bol.Name='zaccc';
        bol.ZAC_PO__c='11111';
        update bol;
        

   
    ICCWorkbench__c wcb  = new ICCWorkbench__c();
    wcb.name ='test';
    wcb.Bill_Lading__c=bol.Id;
    wcb.CurrencyIsoCode='EUR';
   // wcb.Container_Name__c=cont.id;
    insert wcb;
        
      wcb.name='finaltest,suraj,sam';
        update wcb;

    
  
    Container__c cont  = new Container__c();
    cont.name ='bolcont2';
    
     cont.ZAC_Purchase_order_Number__c='testing,myfpo,1111';
    insert cont;
      cont.name ='bolcont3';
       cont.ZAC_Purchase_order_Number__c='testing,myfpo,11111';
       cont.Bill_Of_Lading_Number__c='fire';
    //   cont.
       
       update cont;
      
    }
}

line not cover


            FPOName.add(IccWb.Name);
            fnames=fnames+IccWb.Name+',';

and

bolObj.ZAC_PO__c=fnames;
        update bolObj;
from above class
Best Answer chosen by Suraj Demgunde
Boss CoffeeBoss Coffee
In your test class, you'll need to set ICCWorkbench wcb's Container_Name__c to the container Id so your class fetches it. I see you commented out that line in your test class.
// wcb.Container_Name__c=cont.id;
As for the other section, try setting the BOL_ID__c field on the Container you create in your test class. This is because your class query checks for that field in order to fetch the appropriate records.