You need to sign in to do that
Don't have an account?
Sebastian Page
Some line of apex class is not covered
Hello All
Some line in apex class is not covering please help me.
Some line in apex class is not covering please help me.
public class UpdateAccountManagerEmailAdderss { public Static void updateAccountMgrEmail(List<case> lstcase) { List<String> lstOfDomain=new List<String>(); list <Account> lstAccounts = [Select Id,Account_Manager_Email__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live']; Map<String,String>mapAccount=new Map<String,String>(); for(account a:lstAccounts){ mapAccount.put(a.id,a.Account_Manager_Email__c); } Map<string,string> mapDomain=new Map<String,String>(); for(Account ks:[Select id,institutional_EmailDomain__c from Account WHERE Old_HD_Provider__c!='ConnectWise' AND Status__c='Live' and institutional_EmailDomain__c!=null]) { lstOfDomain.add(ks.institutional_EmailDomain__c); mapDomain.put(ks.institutional_EmailDomain__c, ks.id); } for(case cs:lstcase) { if(lstOfDomain.size()>0){ for(String s:lstOfDomain) { if(cs.Description!=null && ( cs.Description).Contains(s)) { cs.AccountId=mapDomain.get(s); cs.Account_Manager_Email__c=mapAccount.get(cs.AccountId); // cs.Identified_Keyword__c=s; } else { if((cs.Description).Contains('Test1ymail')) { cs.Account_Manager_Email__c='Test1ymail'; } if((cs.Description).Contains('Test2ymail')) { cs.Account_Manager_Email__c='Test2ymail'; } if((cs.Description).Contains('Test3ymail')) { cs.Account_Manager_Email__c='Test3ymail'; } } }}}} } test class is @isTest public class UpdateAccountManagerEmailAdderss_Test { @isTest public static void testAcctMgr() { Map<Id,String> mapAccount =new Map<Id,String>(); Map<String,String> mapDomain=new Map<String,String>(); List<string>lstOfDomain=new List<String>(); Account acc =new Account(); acc.name='BlackeBeltHelp Agents'; // acc.Account_Manager_Email__c='test.test@test.com'; acc.Institutional_EmailDomain__c='ben.edu'; insert acc; mapAccount.put(acc.id,acc.Account_Manager_Email__c); mapDomain.put(acc.Institutional_EmailDomain__c,acc.id); lstOfDomain.add(acc.Institutional_EmailDomain__c); Contact con=new Contact(); con.accountId=acc.id; con.firstName='test'; Con.lastName='testcontact'; Con.Email='Shiv@str.tst'; insert con; Trigger_Control__c tc=new Trigger_Control__c(); tc.name='test'; tc.Enable_Update_Account_Mgr_Email_Trigger__c=true; insert tc; List<case>lstcase=new List<case>(); Case cs=new Case(); cs.accountId=acc.id; cs.contactId=con.id; cs.Account_Manager_Email__c=acc.Account_Manager_Email__c; cs.description='kdjksjkfjkjdfsjmk smjkm'; lstcase.add(cs); insert lstcase; UpdateAccountManagerEmailAdderss.updateAccountMgrEmail(lstcase); } }
Try this test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
Also, the lstOfDomain size is not greater than 0, so the select statement you use to populate it: is not retrieving records based on your test data.
It's always about test data...
Please guide me how to cover 100 % code coverage.
Try this test class:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi