You need to sign in to do that
Don't have an account?

why test class is not covering code coverage for all line
Hi All ,
I have cover only 58 percent code covergage for trigger but i want to 100% . Please understand my test code and tell me what the issue .
my apex trigger is .
Test Class is
Regards
Shiv Patel
I have cover only 58 percent code covergage for trigger but i want to 100% . Please understand my test code and tell me what the issue .
my apex trigger is .
trigger Prevent_Escalation_SupportType on Case (before insert,after update) { List<String> LstRecTypeName=new List<String>{'American Sentinel University_Ticket','Limestone_Ticket','CSU_Ticket','Extension_Ticket','Healthcare Learning Innovations_Ticket','LinnBenton_Ticket','Lipscomb_Ticket', 'Reinhardt University_Ticket','UMKC_Ticket','Bridgeport_Ticket','GardnerWebb_Ticket','Joliet_Ticket','Lynchburg_Ticket','LakeMichiganC_Ticket','RogersState_Ticket','SCKans_Ticket','SewardCCC_Ticket','SUShreveport_Ticket','UTSW_Ticket','Benedictine University_Ticket'}; Set<Id>LstRecordTypIds =new Set<Id>(); List<RecordType> lstrecType=[Select id From RecordType where sobjecttype = 'case' and name in:LstRecTypeName]; for(RecordType Rec:lstrecType) { LstRecordTypIds.add(Rec.id); } for(case cs:trigger.new) { if((userinfo.getLastName().contains('BBH') || (userinfo.getLastName().contains('BlackBeltHelp')))) { if(LstRecordTypIds.contains(cs.RecordTypeId)) { if(cs.Support_Type__c==null) { if(cs.Status=='Action - Automated Escalation' ||cs.Status=='Escalated') { cs.addError('Please select a Support type value before escalating the ticket.'); } } else if(cs.Support_Type__c!=null) { if(!(cs.Status=='Action - Automated Escalation' ||cs.Status=='Escalated')) { cs.addError('Please make sure Support type value is blank unless you want to escalate the ticket'); } } } } } }
Test Class is
@isTest public class Prevent_Escalation_SupportTypeTest { @isTest private static void test1(){ Account acc = new Account(Name='LimeStone'); insert acc; Contact con = new Contact(AccountId=acc.Id,LastName='test'); insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.Enable_CaseCreation_Trigger__c=true; tc.Name='test tc'; insert tc; User u; User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; System.runAs (thisUser) { Profile p = [SELECT Id FROM Profile WHERE Name='CH_Tier1-Partner']; u = new User(alias = 'tstwy', email='testmail@tst.com', emailencodingkey='UTF-8', lastname='testL', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id, ContactId = con.Id, timezonesidkey='America/Los_Angeles', username='testmailxxx@tst.com'); insert u; } List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'Limestone_Ticket']; if(listRecType[0].Id!=null) { System.runAs (u) { Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id ); insert cs; } } } }
Regards
Shiv Patel
try this code

[image: image.png]
Those Number of lines is not covering code coverage after use your code.
Can you check the test class is running successfully or not .. and what is the error message