+ Start a Discussion
maiyakumaiyaku 

Code Coverage 46% I can add it to me?

Average Code now 46% I can Add to me?

 

 

trigger ContractsSync on Contracts__c(after insert) {
for(Contracts__c COL:trigger.new){
        if(COL.id != Null ){
        
        Quotes_Line_Item__c[] QuoLine= [Select Id, Name,QuotesID__c,Plant_Manager_Acceptation__c,Unit_Price__c,Quantity__c,Total_Weight__c From Quotes_Line_Item__c  where QuotesID__c= :COL.Quotes__c And Plant_Manager_Acceptation__c = 'Accept'];
            
            Contracts_LineItem__c[] CLI = new Contracts_LineItem__c[]{};
            Contracts_LineItem__c CL = new Contracts_LineItem__c();
              
                
                for(Quotes_Line_Item__c QL: QuoLine){
                
                CL = new Contracts_LineItem__c();
                CL.Contracts__c = COL.id;
                CL.Quotes_Line_Item__c = QL.Id;              
                CL.Unit_Price__c = QL.Unit_Price__c;
                CL.Quantity__c = QL.Quantity__c;
                CL.Total_Weight__c = QL.Total_Weight__c;
                CL.Name = QL.Name;             
                CLI.add(CL);     
                }
                insert CLI;
          }
        
    }
}

 Test

 

@isTest
private class TestContractsSync{

   static testMethod void myUnitTest() {
        Account Acc = new Account(Name='test');
        insert Acc;
       Opportunities__c O = new Opportunities__c(Account_Name__c=Acc.Id,Stage__c='Prospecting');
       insert O;
        
        Quotes__c Q = new Quotes__c(OpportunitiesID__c=O.Id);
        insert Q;
                
        Opportunities_Line_Item__c OL = new Opportunities_Line_Item__c(OpportunitiesID__c=O.Id);
        insert OL;
        
        Quotes_Line_Item__c QL = new Quotes_Line_Item__c(Name =OL.Name,QuotesId__c=Q.Id,Opportunities_Line_Item__c=OL.Id);
        insert QL;
        
        Contracts__c COT = new Contracts__c(Quotes__c = Q.id);
        insert COT;
        
        Contracts_LineItem__c COL =  new Contracts_LineItem__c(Name='Test',Quotes_Line_Item__c = QL.id,Contracts__c = COT.id);
        insert COL;
        
    } 
}

 

 

Thank you so much.