You need to sign in to do that
Don't have an account?
bonny mankotia
I have a simple trigger but enable to cover the code coverage please anyone idea about this?
trigger ClosedOpportunityTrigger on Opportunity (before insert)
{
list<task> carry = new list<task>();
for(opportunity opp: trigger.new)
{
if(opp.StageName == 'Closed Won')
{
task t = new task(whatid=opp.id,Subject = 'Follow Up Test Task');
carry.add(t);
}
}
insert carry;
}
Here is my test class
@isTest
public class TestOppTrig
{
static testmethod void testFun()
{
Opportunity opp = new opportunity();
opp.Name = 'Bob';
opp.StageName = 'closed won';
opp.CloseDate = system.today();
insert opp;
task t = new task();
t.whatid=opp.id;
t.subject = 'dasfsdfds';
insert t;
}
}
{
list<task> carry = new list<task>();
for(opportunity opp: trigger.new)
{
if(opp.StageName == 'Closed Won')
{
task t = new task(whatid=opp.id,Subject = 'Follow Up Test Task');
carry.add(t);
}
}
insert carry;
}
Here is my test class
@isTest
public class TestOppTrig
{
static testmethod void testFun()
{
Opportunity opp = new opportunity();
opp.Name = 'Bob';
opp.StageName = 'closed won';
opp.CloseDate = system.today();
insert opp;
task t = new task();
t.whatid=opp.id;
t.subject = 'dasfsdfds';
insert t;
}
}
Overall, you test class has everything you need for a positive test. Once you insert the Opportunity, just confirm that a related task has been created by the trigger. This should work as long as your trigger is working.
All Answers
Overall, you test class has everything you need for a positive test. Once you insert the Opportunity, just confirm that a related task has been created by the trigger. This should work as long as your trigger is working.
First please run your trigger after insert because in before insert you can not get the whatid in the task so please use the below code:
and your triggerr cover 100% code coverage.
Thanks
Gyani
http://www.mirketa.com