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
Sebastian PageSebastian Page 

code coverage not increasing in my apex trigger

Hi all,

code coverage not increasing in my apex trigger please help me
my apex code is 


trigger autoCreateContactController on Case (before insert) {
        
for(case cs:Trigger.new)
    {
           if(lstBasedOnDesc.size()>0)
            { 
                for(String s:lstBasedOnDesc)
                { 
                     
                     if((cs.SuppliedEmail).Contains(s))
                    {
                        cs.ownerId='00Gd00000027kH7';
                   } 
                    else {
            List<contact> lstcontact= [select id from contact where email=:cs.SuppliedEmail limit 1];
                
                 if(lstcontact.size()>0)
                 {
                    cs.ContactId=lstcontact.get(0).id;
                 }
               
                    else{
                   String leftPart = cs.SuppliedEmail.substringBefore('@');
                        if(leftPart.contains('.')){
                    String[] leftPartSplitted = leftPart.split('\\.');
                            
                   //we check if there's one dot in the substring
                  if(leftPartSplitted.size() == 2 ){
                  String firstName = leftPartSplitted[0];
                String lastName = leftPartSplitted[1];
                   contact con1 =new contact();
                    con1.firstname=firstName;
                    con1.LastName=lastName;
                    con1.Email=cs.SuppliedEmail;
                    con1.AccountId='0010W00002MuDcQ';
                    insert con1;
                    
                    cs.ContactId=con1.Id;
                    }
                        
                        }
                       
                        else if(leftPart.contains('_')){
                         String[] leftPartSplitted = leftPart.split('\\_');
                            if(leftPartSplitted.size()==2)
                        {
                    String firstName = leftPartSplitted[0];
                   String lastName = leftPartSplitted[1];
                   contact con1 =new contact();
                    con1.firstname=firstName;
                    con1.LastName=lastName;
                    con1.Email=cs.SuppliedEmail;
                    con1.AccountId='0010W00002MuDcQ';
                    insert con1;
                    
                    cs.ContactId=con1.Id;  
                        }
                    
                        }
                        else{
                    String firstName = 'unkown';
                   String lastName = leftPart;
                   contact con1 =new contact();
                    con1.firstname=firstName;
                    con1.LastName=lastName;
                    con1.Email=cs.SuppliedEmail;
                    con1.AccountId='0010W00002MuDcQ';
                    insert con1;
                    
                    cs.ContactId=con1.Id;    
                            
                        }}}}}}

and my test class is 


@isTest
public class AutoCreateContactControllerTest {

@isTest
    public Static void SpamTestmethod()
    { Account acc = new Account(Name='test11');
        insert acc;
        
        Contact con = new Contact(AccountId=acc.Id,LastName='test',Email='desd.red@test.tst');
        insert con;
        Trigger_Control__c tc=new Trigger_Control__c();
       tc.Enable_Spam_Controller_Trigger__c=true;
        tc.Name='test tc';
        insert tc;
      User u;
        User thisUser = [SELECT Id FROM User WHERE Id = '005d000000187CwAAI'];        
        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<case>lstcase=new List<case>();
       List<RecordType> listRecType = [select Id from RecordType where sObjectType = 'Case' And Name = 'MassBayCC_Ticket'];     
      System.runAs (u) {
            Case cs = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
          cs.Spam_criteria__c='Based on Description';
        cs.Subject='tesr';
        cs.Description='tjkjkjksj kljkjsldk';
        cs.SuppliedEmail='shr.jdd@test.com';
        cs.Possible_Spam__c=true;
        cs.Identified_Keyword__c='s';
          lstcase.add(cs);
          Case cs1 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
          cs1.Spam_criteria__c='Based on Webmail';
        cs1.Subject='tesr';
        cs1.Description='tjkjkjksj kljkjsldk';
        cs1.SuppliedEmail='shr.jdd@test.com';
        cs1.Possible_Spam__c=true;
        cs1.Identified_Keyword__c='s';
          lstcase.add(cs1);
          Case cs2 = new Case(RecordTypeId = listRecType[0].Id,AccountId=acc.Id,ContactId=con.Id);
          cs2.Spam_criteria__c='Based on Subject';
        cs2.Subject='tesr';
        cs2.Description='tjkjkjksj kljkjsldk';
        cs2.SuppliedEmail='shr.jdd@test.com';
        cs2.Possible_Spam__c=true;
        cs2.Identified_Keyword__c='s';
        
        lstcase.add(cs2);
          insert lstcase;
          
       }
    }
}
please help me i am got 18% code coverage