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
KyoKyo 

Update CodeCoverage in TestClass

Test Class is not full loop . it's problem 1 line in Testclass

Coverage is 85% now

 

trigger ChangeStatusinOBC on Out_Bound_Call_List__c (Before insert,Before Update) {
// You can change status equal Complete when RelatedList OB Contact status all Complete
set<ID> setOBLID = new set<ID>();

    

    for(Out_Bound_Call_List__c OBL : Trigger.new){
            setOBLID.Add(OBL.ID);      
    } // Add id for Query
    
    List<OutBound_Contact__c> lstOBC = [Select id from OutBound_Contact__c where  Out_Bound_Call_List__c in : setOBLID]; // Query OutBound Contact List
    System.debug('Error SOQL');
    
    for(Out_Bound_Call_List__c OBL : Trigger.new){
        if((lstOBC.size() != OBL.Count_Complete__c) && lstOBC.size() != 0 && OBL.Status__c == 'Completed'){
            Trigger.new[0].Status__c.AddError('Status in OutBound Contact all not equal to contacted');
        }// Set Error in Field Status 
    }

}

 

a problem line : 

if((lstOBC.size() != OBL.Count_Complete__c) && lstOBC.size() != 0 && OBL.Status__c == 'Completed'){

 

@isTest 
private class TestChangeStatusinOBC {
    static testMethod void myTest() {
    
        Out_Bound_Call_List__c OBL = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        insert OBL;
        
        OutBound_Contact__c OBC = new OutBound_Contact__c();
        OBC.Out_Bound_Call_List__c = OBL.id;
        OBC.Status__c = 'Contacted';
        insert OBC;
        update OBC;
        
        Out_Bound_Call_List__c OBL1 = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        OBL.Status__c = 'Completed';
        test.startTest();
        Try{
            insert OBL;
            update OBL;
        }
        catch (Exception e) {   
            System.Debug('Status in OutBound Contact all not equal to contacted');
        }
        test.stopTest();
    
    
    }
}

 

Thank you so much.

Shashikant SharmaShashikant Sharma

Here is your test class

 

@isTest 
private class TestChangeStatusinOBC {
    static testMethod void myTest() {
    
        Out_Bound_Call_List__c OBL = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        insert OBL;
        
        OutBound_Contact__c OBC = new OutBound_Contact__c();
        OBC.Out_Bound_Call_List__c = OBL.id;
        OBC.Status__c = 'Contacted';
        insert OBC;
        
        OutBound_Contact__c OBC1 = new OutBound_Contact__c();
        OBC1.Out_Bound_Call_List__c = OBL.id;
        OBC1.Status__c = 'Contacted';
        insert OBC1;
        
        test.startTest();
        try
        {
            OBL.Status__c = 'Completed';
            OBL.Count_Complete__c = 1;
            update OBL;
        }
        catch (Exception e) {   
            System.Debug('Status in OutBound Contact all not equal to contacted');
        }
        test.stopTest();
    }
}

 Let me know if any issues in it.

maiyakumaiyaku

Thank for Answer but error change after edit Test class

 

Trigger.new[0].Status__c.AddError('Status in OutBound Contact all not equal to contacted');

 

and Field OBL.Count_Complete__c not writeable because Type Rollup summary 

 

Thank you so much.


Shashikant SharmaShashikant Sharma

Ok I was not aware it is a rollup sumary field., try this , if it does not work please let me know what does this rollup summary field Count_Complete__c represents.

@isTest 
private class TestChangeStatusinOBC {
    static testMethod void myTest() {
    
        Out_Bound_Call_List__c OBL = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        insert OBL;
        
        OutBound_Contact__c OBC = new OutBound_Contact__c();
        OBC.Out_Bound_Call_List__c = OBL.id;
        OBC.Status__c = 'Contacted';
        insert OBC;
        
        OutBound_Contact__c OBC1 = new OutBound_Contact__c();
        OBC1.Out_Bound_Call_List__c = OBL.id;
        OBC1.Status__c = 'Contacted';
        insert OBC1;
        
        test.startTest();
        try
        {
            OBL.Status__c = 'Completed';
            update OBL;
        }
        catch (Exception e) {   
            System.Debug('Status in OutBound Contact all not equal to contacted');
        }
        test.stopTest();
    }
}

 

maiyakumaiyaku

I'm edit Test class from ex.

 

//OBL.Count_Complete__c = 1; 

 

but error hilight 

Trigger.new[0].Status__c.AddError('Status in OutBound Contact all not equal to contacted');

I can not fix it.

 

Thank you.