You need to sign in to do that
Don't have an account?
Taresh Pandey 19
How to get test coverage in nested IF ELSE condition ?
Hi Mates,
I have wrote a trigger on task but i'm not able to get test coverage in side nested IF ELSE condition, can anyone suggest me, how can I bring this code into testCoverage. Please refer following code.
Test Class :
Any help would be appreciated, please reply ASAP
Regards'
Taresh
I have wrote a trigger on task but i'm not able to get test coverage in side nested IF ELSE condition, can anyone suggest me, how can I bring this code into testCoverage. Please refer following code.
if(Trigger.isAfter){ if(Trigger.isInsert ||Trigger.isUpdate){ Set<ID> ContactIDis = new Set<ID>(); list<Contact> Con_logs = new list<Contact>(); for(Task tasklogs: trigger.new){ ContactIDs.add(tasklogs.WhoId); } for(Contact conlogs : [SELECT Id, Name, Contact_Status__c, Next_Follow_Up_Date__c,(SELECT ID, AccountId, Activity__c, CallDisposition, CallObject, CallType, Contact_Name__c, CreatedDate, Subject, WhatId, WhoId FROM Tasks ///ORDER BY CallDisposition ASC NULLS LAST )FROM Contact Where ID IN :ContactIDis ]){ try{ for(Task tasklogs : conlogs.Tasks){ if(tasklogs.CallDisposition == 'Do Not Disturb' || tasklogs.CallDisposition == 'Negative' ){ conlogs.Contact_Status__c = 'Negative'; }else if(tasklogs.CallDisposition == 'Voice Mail'){ conlogs.Next_Follow_Up_Date__c = System.today()+1; }else if(tasklogs.CallDisposition == 'No Response' || tasklogs.CallDisposition == 'Person Unavailable' || tasklogs.CallDisposition == 'Person Busy'){ conlogs.Next_Follow_Up_Date__c = System.today()+2; }else{ conlogs.Next_Follow_Up_Date__c = Null; } Con_logs.add(conlogs); } }catch(exception e){ system.debug('Got an exception'); } } upsert Con_logs; } }I'm not getting coverage in the bold highlighted area.
Test Class :
@isTest private class TaskUpdateContact_Test { static testmethod void test_trigger(){ List<Contact> l = new List<Contact>(); List<Task> task_list = new List<Task>(); Account acc = new Account(Name = 'testAccount'); insert acc; Contact a =New Contact(); // creating new contact a.LastName='Sri'; a.MailingCountry='INDIA'; a.MailingCity='Mumbai'; a.Email='abc@example.com'; a.Phone='11111111'; a.AccountID = acc.ID; a.Next_Follow_Up_Date__c = system.today(); insert a; //Creating new task Task task1= new task(); task1.Subject='Call'; task1.status='Completed'; task1.Whoid=a.id; task1.ActivityDate=Date.Today(); task1.CallDisposition ='Negative'; task1.FastCall__Call_Notes__c = 'abc'; task_list.add(task1); insert task_list; // Updating existing contact test.startTest(); if(task1.CallDisposition == 'Voice Mail'){ a.MailingCity = 'Pune'; a.Next_Follow_Up_Date__c = system.today()+3; //a.ID = task1.whoID; }else if(task1.CallDisposition == 'Negative'){ a.Contact_Status__c = 'Negative'; } update a; l.add(a); //test.startTest(); upsert l; test.stopTest(); } }
Any help would be appreciated, please reply ASAP
Regards'
Taresh
Please check once below sample code :
Hope this helps.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
let me share my complete code with you, I think that might help you to find actual problem
refer the following code please.
you can see the test class in my question.
Regards'
Taresh