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
Jyoti Sahoo 3Jyoti Sahoo 3 

Can some one help me in writing the test class

Hi, Can someone please help me writing the test class for the below trigger - 

 
trigger UpdateStatus on Advisement__c (after update) {

    List<Case> parentObjList = new List<Case>();
    List<Advisement__c> childObjList = new List<Advisement__c>();
    List<Id> listIds = new List<Id>();

    
    Integer i=0;
    Integer count = 0;

    for (Advisement__c childObj : Trigger.old) {
        Case co = [Select Id, Status from Case where Id =: childObj.Case__c];

        childObjList = [SELECT id,Case__c, Status__c FROM Advisement__c where Case__c =:co.Id];
        
        for (Advisement__c adv : childObjList){
           
            if(adv.Status__c == 'Done' || adv.Status__c == 'Approved with Signature' || adv.Status__c == 'Declined')
            {
              i = 0;
              count = count + 1;
              }
              
            else
            {
              i = 1;
        
            }
         }
            if ( childObjList.size() == count) {
                
                    co.Status = 'Final Review';
                    }
            else{
                    co.Status = 'In Progress';
                }
                    
    update co;
            
        
    }
SwethaSwetha (Salesforce Developers) 
HI Jyoti,
The below articles give a good insight into how to begin writing test class and how coverage can be improved

https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines 

Examples: https://developer.salesforce.com/forums/?id=906F000000090H2IAI
https://salesforce.stackexchange.com/questions/24551/test-class-for-after-insert-update-trigger

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you