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

How to increase the code coverage for the this trigger?
Hi guys,
My code coverage is at 77% at this time and I need to increase it or try to get it 100%. Here' s the red section which is not covered.

and here 's the test code.
How do I increase the code coverage from here? What am I missing the test class?
My code coverage is at 77% at this time and I need to increase it or try to get it 100%. Here' s the red section which is not covered.
and here 's the test code.
Account acc = new Account(); acc.Name ='Test'; insert acc; Contact cont = new Contact(); cont.FirstName ='Test'; cont.LastName ='testContact'; cont.Last_Activity_Subject__c='Run Test Trigger'; cont.accountid =acc.id; cont.Last_Activity_Date__c = Date.parse('6/15/2019'); insert cont; Task u = new Task(); u.ownerId = UserInfo.getUserId(); u.whatid = acc.id; u.whoid = cont.id; u.Subject='Run Test Trigger'; u.Status='Not Started'; u.Priority='Normal'; u.ActivityDate = Date.parse('6/15/2019'); insert u; Test.startTest(); update u; for (Task t : [SELECT Id, Subject, Status FROM Task WHERE Id = :cont.Id]) { System.assertEquals('Run Test Trigger',t.Subject); // asserts that your test worked properly System.assertEquals('Not Started', t.Status); // asserts that your test worked properly } for (Contact u1 : [SELECT Id, Last_Activity_Subject__c, Last_Activity_Date__c FROM Contact WHERE Id = :cont.Id]) { System.assertEquals('Run Test Trigger', u1.Last_Activity_Subject__c); // asserts that your test worked properly } Test.stopTest();
How do I increase the code coverage from here? What am I missing the test class?
if(t.ActivityDate >= l.Last_Activity_Date__c)
Also update the query for the assert statement for Task as below
for (Task t : [SELECT Id, Subject, Status FROM Task WHERE whoId = :cont.Id])
Let me know if it working and covering the lines highlighted in red.
All Answers
if(t.ActivityDate >= l.Last_Activity_Date__c)
Also update the query for the assert statement for Task as below
for (Task t : [SELECT Id, Subject, Status FROM Task WHERE whoId = :cont.Id])
Let me know if it working and covering the lines highlighted in red.
Thanks again!