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

Test Class Assist Please on working Trigger
Someone was kind enough to help me work through to get the following trigger, now I need some help building test coverage so I can deploy. thanks.
trigger NextTaskInfo on Task (after insert, after update) { if(Trigger.new.size() == 1 ) { Task tk = Trigger.New[0]; String str = tk.whatid; if(str != null && str.substring(0,3)== '006') { Opportunity opp = [select OwnerId,NextTaskSubject__c,Next_Task_Date__c from Opportunity where Id = :tk.WhatId ]; List<Task> tskMin = [Select ActivityDate,Subject From Task where whatid=:tk.whatid and what.type = 'Opportunity' and isClosed = false order By ActivityDate limit 1]; if (tskMin.size()>0) { opp.Next_Step_Date__c=tskMin[0].ActivityDate; opp.NextTaskSubject__c=tskMin[0].Subject; } else { opp.Next_Step_Date__c=null; opp.NextTaskSubject__c=''; } update opp; } } }
Hi,
Below is your test class code. It will give you 100% test coverage.
@isTest
private class TestClassTaskTrigger {
static testMethod void testDiscussionBoardTrigger() {
Opportunity testOpp = new Opportunity( Name ='TestOpp', StageName ='Prospecting', CloseDate = System.today()+60);
insert testOpp;
System.assert(testOpp != null);
Task testTask = new Task (WhatId = testOpp.Id,Subject = 'Other', Status ='In Progress');
insert testTask;
System.assert(testTask != null);
Task edTask = [Select t.WhatId, t.Subject, t.Status From Task t where t.Id=:testTask.Id];
edTask.Status = 'Completed';
update edTask;
}
}
thanks, this seems to be working, but I cannot deploy b/c I have two existing triggers in production that i lack test coverage for.
I appreciate the help. I am an admin who trying to expand my powers to include developer/coding...
and