You need to sign in to do that
Don't have an account?
Test class coverage help needed
Hi,
I have a trigger for which i have written a test class for it , it covers 72% , i want to increase more than it , not able to figure out how to increase,
My Trigger
/**
**
**/
trigger AF_processETBouncebacks on et4ae5__IndividualEmailResult__c (after insert) {
Map<String,String> aeMap = new Map<String,String>();
List<Case> casesToInsert = new List<Case>();
List<Task> tasksToInsert = new List<Task>();
List<et4ae5__IndividualEmailResult__c> bouncedEmails = new List<et4ae5__IndividualEmailResult__c>();
Map<String,String> acEmailMap = new Map<String,String>();
for (et4ae5__IndividualEmailResult__c bouncedEmail: Trigger.New) {
if (bouncedEmail.et4ae5__HardBounce__c) {
bouncedEmails.add(bouncedEmail);
}
}
if (bouncedEmails.size() > 0) {
for (et4ae5__IndividualEmailResult__c tempList : [Select et4ae5__Contact__r.AccountId from et4ae5__IndividualEmailResult__c Where Id IN :bouncedEmails]){
acEmailMap.put(tempList.Id,tempList.et4ae5__Contact__r.AccountId);
}
Map<String, RecordType> caseRecordTypeMap = AF_DealerCRM_Utility.getRecordTypes('Case');
Map<String,Group> dealerCrmQueueMap = AF_DealerCRM_Utility.getDealerCrmQueue();
aeMap = AF_DealerCRM_Utility.getAE(acEmailMap.values());
for (et4ae5__IndividualEmailResult__c email: bouncedEmails) {
String acId = acEmailMap.get(email.id);
if (aeMap.containsKey(acId)) {
Task tsk = new Task();
tsk.WhoId = email.et4ae5__Contact__c;
tsk.OwnerId = aeMap.get(acId);
tsk.Subject = 'Bounceback Correction';
tsk.ActivityDate = date.today()+5;
tsk.CreatedById = System.Label.ExactTarget_Admin;
tsk.Description = 'There was a bounceback for this Contact. The email send id : ' + email.et4ae5__SendDefinition__c;
tasksToInsert.add (tsk);
}
else {
// If no Autofinance AE or Additional AE exists, then create a case and assign to Sales Performance Queue.
Case cs = new Case();
cs.AccountId = acId;
cs.Priority = 'Medium';
cs.Subject = 'No AE found on Account Team';
cs.Status = 'New';
cs.Description = 'Please navigate to the contact on this case to re-assign the task owner';
cs.ContactId = email.et4ae5__Contact__c;
cs.Case_related_to__c = 'Contact';
cs.RecordTypeId = caseRecordTypeMap.get('Sales').Id;
cs.OwnerId = dealerCrmQueueMap.get('Case Mgmt Sales Performance').Id;
casesToInsert.add(cs);
}
}
/* New Cases for AE that are not found.*/
if (casesToInsert.size() > 0 ) {
try {
AF_DealerCRM_DML_Utility.insert_op(casesToInsert);
}
catch(Exception ex) {
system.debug('Exception while creating Case' + ex.getMessage());
}
}
/* New Tasks to create for bounced emails */
if (tasksToInsert.size() > 0) {
try {
AF_DealerCRM_DML_Utility.insert_op(tasksToInsert);
}
catch(Exception ex) {
system.debug('Exception while creating Tasks for bounced emails : ' + ex.getMessage());
}
}
}
}
My Test class :
@isTest
public class AF_processETBouncebacks{
testMethod static void testProcessBouncebacksTrigger() {
Test.startTest();
// Create a few records to test various scenarios
contact con = new contact();
con.LastName ='c';
insert con;
Account acc = new Account();
acc.Name ='Test';
insert acc;
et4ae5__IndividualEmailResult__c emailresult = new et4ae5__IndividualEmailResult__c();
emailresult.et4ae5__Contact__c =con.id;
//emailresult.et4ae5__Contact__r.AccountId=acc.id;
emailresult.et4ae5__DateBounced__c =date.today();
emailresult.et4ae5__HardBounce__c = true;
emailresult.et4ae5__Opened__c = true;
insert emailresult;
Task tsk = new Task();
tsk.WhoId =con.id;
//tsk.OwnerId = aeMap.get(acId);
tsk.Subject = 'Bounceback Correction';
tsk.ActivityDate = date.today()+5;
//tsk.CreatedById = System.Label.ExactTarget_Admin;
tsk.Description = 'There was a bounceback for this Contact. The email send id : ';
insert tsk;
Case cs = new Case();
cs.AccountId = acc.Id;
cs.Priority = 'Medium';
cs.Subject = 'No AE found on Account Team';
cs.Status = 'New';
cs.Description = 'Please navigate to the contact on this case to re-assign the task owner';
cs.ContactId = con.Id;
cs.Case_related_to__c = 'Contact';
insert cs;
Test.stopTest();
//Task createdTasks = [Select Id,WhoId ,OwnerId ,Subject ,ActivityDate,Description from Task Where WhoId IN:emailresult];
// verify if target tasks etc are created successfully
//System.assert(tsk);
}
}
i also want to add system.assert statement to my test class , can that increase my coverage
kindly help me on this class
Thanks in Advnce
All Answers
Thanks, it worked