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
Smurfet15Smurfet15 

Need help for Auto create Test Class

Hi Guro,

I have trigger that is working but my testclass is only  coverage code 36%:
Can you please help to make my code coverage 100% or close to it?
Here is test class and below is my trigger.
--------------------------------------------------------------
@isTest
private class TESTCLASS_AutoCreateWork {
    static testMethod void testCreateWork(){
    controlTriggerRun.autoCreateWork_run = true;
        Case c = new Case();
        c.recordtypeID = '0123B0000004Hzg';
        c.status = 'new';
        c.origin = 'email';
        c.subject = 'Test work item';
        c.description = 'Test to see if a work item is created';
        c.type = 'change';
        insert c;
    
        agf__ADM_Work__c w = new agf__ADM_Work__c();
          w.agf__Subject__c = c.Subject;
          w.agf__Description__c = c.Description;
          w.agf__Status__c = 'New';
          w.Case__c = c.id;
          w.agf__Assignee__c = c.OwnerId;
          w.agf__Product_Owner__c = c.Requestor_Name__c;
          w.agf__Priority_Rank__c = 1;
          w.agf__Use_Prioritizer__c = true;
         
     Test.startTest();
       insert w;  
       list<agf__ADM_Work__c>  ws = [Select Id,  agf__Subject__c , agf__Description__c , case__c  From agf__ADM_Work__c where Case__c =: c.Id];
       system.assertEquals(1,ws.size());
    agf__ADM_Work__c ws1 = ws[0];
   Test.stopTest();
    }
}

Here is trigger:
--------------------------------------------------------------------------------------------------------
trigger autoCreateWork on Case (after update, after insert) {
list<agf__ADM_Work__c> workitems = new list<agf__ADM_Work__c>();
    if(controlTriggerRun.autoCreateWork_run ){
        if(trigger.isinsert){
           for(case c : trigger.new){
               RecordType caseRecType = [Select Name from RecordType where id = : c.recordtypeID];
                if(caseRecType.Name == 'change'){
                    agf__ADM_Work__c w = new agf__ADM_Work__c();
                    w.agf__Subject__c = c.Subject;
                    w.agf__Description__c = c.Description;
                    w.agf__Status__c = 'New';
                    w.Case__c = c.id;
                    w.agf__Assignee__c = c.OwnerId;
                    w.agf__Product_Owner__c = c.Requestor_Name__c;
                    w.agf__Priority_Rank__c = 1;
                    w.agf__Use_Prioritizer__c = true;
                    workitems.add(w);
                    system.debug('Maryx' + c.ownerid);
                    system.debug('Maryx1' + c.Requestor_Name__c);
                }
            }
        }
 
     if(workitems.size()>0){
           controlTriggerRun.autoCreateWork_run = false;
            upsert workitems;
     }
   }
}