You need to sign in to do that
Don't have an account?
fiona gentry
Trigger test class not showing coverage
Dear folks,
Wrote the test class for Trigger test class ,can't see the coverage ,can someone review the class and suggest the fix
Here is the Trigger apex which has label EmailSubjectAsw and the label has value 'Airtel'
Your help is appreciated
Regards
Fiona
Wrote the test class for Trigger test class ,can't see the coverage ,can someone review the class and suggest the fix
@isTest private class EmailSubjectAswTest { private static testmethod void EmailSubjectAswTestTest(){ Id RecordTypeIdCase = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Executive Rep').getRecordTypeId(); Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email',RecordTypeId = RecordTypeIdCase,Subject = 'Airtel'); insert cas; } }
Here is the Trigger apex which has label EmailSubjectAsw and the label has value 'Airtel'
trigger PrepaidEmailSubjectAsw on Case (before insert) { String searchWords; List<String> strings; List<Group> lstPre = [SELECT Id from Group where Type = 'Queue' AND DeveloperNAME = 'Prepaid_Queue' LIMIT 1]; id rtid = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('Executive Rep').getRecordTypeId(); if(Trigger.isbefore && Trigger.IsInsert){ for (Case c : Trigger.new) { searchWords = Label.EmailSubjectAsw; strings = searchWords.split(','); if(c.Subject!=Null && c.RecordTypeId==rtid && lstPre.size() > 0){ if (isStringInTarget(strings, c.Subject)) { c.OwnerId =lstPre[0].id; } } } } public static Boolean isStringInTarget(List<String> strings, String target) { String strRegEx = '(?i)\\b('; for (String s : strings) { strRegEx = strRegEx + s + '|'; } strRegEx = strRegEx.removeEnd('|'); strRegEx = strRegEx + ')\\b'; Matcher matcher=Pattern.compile(strRegEx).matcher(target); Boolean result= matcher.find(); return result; } }
Your help is appreciated
Regards
Fiona
You need to modify your trigger and you shouldn't write the apex method inside trigger, instead of that you need to create class and refer the class method in trigger.
I have modified your trigger and test class.
trigger:
Test Class: You were quering the the account recordtype instead of case recordtype. I have modified and getting 100%
If this helps, Please mark it as best answer.
Thanks!!
All Answers
You need to modify your trigger and you shouldn't write the apex method inside trigger, instead of that you need to create class and refer the class method in trigger.
I have modified your trigger and test class.
trigger:
Test Class: You were quering the the account recordtype instead of case recordtype. I have modified and getting 100%
If this helps, Please mark it as best answer.
Thanks!!
Please follow below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh