You need to sign in to do that
Don't have an account?
Nancy Gresham
Assistance with test class for case trigger
Hi All!
I'm having trouble writing a test for this trigger. I can get 65% coverage, but not more. I'm new to this, so I'm sure there is something small I'm missing somewhere. Any help would be awesome! Thanks!
I'm having trouble writing a test for this trigger. I can get 65% coverage, but not more. I'm new to this, so I'm sure there is something small I'm missing somewhere. Any help would be awesome! Thanks!
trigger CaseResolutionTrigger on Case (after update) { Set<String> caseIdSet = new Set<String>(); if(CaseResolutionTriggerHandler.isFirstTime) { CaseResolutionTriggerHandler.isFirstTime = false; Set<ID> RTIds = new Set<ID>(); //set of Record Type IDs to match List<CaseComment> CommentList = new List<CaseComment>(); List<Time_Entry__c> TEList = new List<Time_Entry__c>(); for(RecordType rt : [select id from Recordtype where SobjectType='Case' and ((Name like 'e-MDs%') or (Name like 'Richmond%'))]){ RTIds.add(rt.id); } for(Case ca : Trigger.New) { //Only when Resolution is changed and only for specified Record Types - Insert Comment and Time Entry if(RTIds.contains(ca.Recordtypeid) && ca.Resolution__c != '' && ca.Resolution__c != Trigger.oldmap.get(ca.id).Resolution__c){ CaseComment com = new CaseComment(); com.ParentId = ca.id; com.CommentBody= 'RESOLUTION: '+ '\n' + ca.Resolution__c; CommentList.add(com); Time_Entry__c te = new Time_Entry__c(); te.Case__c = ca.id; te.Minutes_Spent__c = ca.Minutes_SMB__c; TEList.add(te); } //clear the number passed from the case to the Time Entry Case c = [Select id, Minutes_SMB__c from Case where id = :ca.id]; c.Minutes_SMB__c = NULL; update c; } Insert CommentList; Insert TEList; } }
Try to update your code like below
Try to bulky your Trigger as well
Try to avoid SOQL inside for loop.
All Answers
Can you please share your test class so i can make necessary change in that.
Thanks
Hemant
Try to update your code like below
Try to bulky your Trigger as well
Try to avoid SOQL inside for loop.