• JGillespie
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

My Apex Trigger works properly, but I'm having trouble with my test. Below is by test method:

 

@isTest
private class taskUpdateLeadStatusTests {

static testMethod void validateUpdateLeadStatusWithCall() {

Lead l = new Lead (LastName='Phillips', Company='Phil Inc.');
l.Status = 'Open';
insert l;

Task t = new Task();
t.Subject = 'Call';
t.Status = 'Completed';
t.WhoId = l.Id;
insert t;

System.assertEquals(l.Status, 'Contacted');

}

static testMethod void validateUpdateLeadStatusWithEmail() {

Lead l = new Lead (LastName='Phillips', Company='Phil Inc.');
l.Status = 'Open';
insert l;

Task t = new Task();
t.Subject = 'Email';
t.Status = 'Completed';
t.WhoId = l.Id;
insert t;

System.assertEquals(l.Status, 'Contacted');

}

}

 

 

Here is the trigger associated with the test:

 

trigger taskUpdateLeadStatus on Task (after insert, after update) {

list<lead> liLeads = new list<lead>();
list<id> liIds = new list<id>();

for(Task sTask : trigger.new)
{
if(sTask.Status == 'Completed' && (sTask.Subject == 'Call' || sTask.Subject == 'Email'))
{
liIds.add(sTask.WhoId);
}
}

for(Lead sLead : [select Id, Status from Lead where Id in : liIds])
{
sLead.Status = 'Contacted';
liLeads.add(sLead);
}

update liLeads;

}

 

 

Can someone provide guidance on this topic? 

 

Thanks,

I'm trying to trigger a Lead Status change to 'Contacted' upon the completion of a task (email or phone call). Here's what I have setup in the Task Triggers, but it's not working. Can anyone see why this isn't working?

 

  trigger taskUpdateLeadStatus on Task (after update) {


    list<lead> liLeads = new list<lead>();
    list<id> liIds = new list<id>();
    
    for(Task sTask : trigger.new)
    {
        if(sTask.Status == 'Completed' && sTask.Subject == 'Call')
        {
            liIds.add(sTask.WhoId);
        }
    }
    
    for(Lead sLead : [select Id, Status from Lead where Id in : liIds])
    {
        sLead.Status = 'Contacted';
        liLeads.add(sLead);
    }
    
    update liLeads; 
    
}

My Apex Trigger works properly, but I'm having trouble with my test. Below is by test method:

 

@isTest
private class taskUpdateLeadStatusTests {

static testMethod void validateUpdateLeadStatusWithCall() {

Lead l = new Lead (LastName='Phillips', Company='Phil Inc.');
l.Status = 'Open';
insert l;

Task t = new Task();
t.Subject = 'Call';
t.Status = 'Completed';
t.WhoId = l.Id;
insert t;

System.assertEquals(l.Status, 'Contacted');

}

static testMethod void validateUpdateLeadStatusWithEmail() {

Lead l = new Lead (LastName='Phillips', Company='Phil Inc.');
l.Status = 'Open';
insert l;

Task t = new Task();
t.Subject = 'Email';
t.Status = 'Completed';
t.WhoId = l.Id;
insert t;

System.assertEquals(l.Status, 'Contacted');

}

}

 

 

Here is the trigger associated with the test:

 

trigger taskUpdateLeadStatus on Task (after insert, after update) {

list<lead> liLeads = new list<lead>();
list<id> liIds = new list<id>();

for(Task sTask : trigger.new)
{
if(sTask.Status == 'Completed' && (sTask.Subject == 'Call' || sTask.Subject == 'Email'))
{
liIds.add(sTask.WhoId);
}
}

for(Lead sLead : [select Id, Status from Lead where Id in : liIds])
{
sLead.Status = 'Contacted';
liLeads.add(sLead);
}

update liLeads;

}

 

 

Can someone provide guidance on this topic? 

 

Thanks,

I'm trying to trigger a Lead Status change to 'Contacted' upon the completion of a task (email or phone call). Here's what I have setup in the Task Triggers, but it's not working. Can anyone see why this isn't working?

 

  trigger taskUpdateLeadStatus on Task (after update) {


    list<lead> liLeads = new list<lead>();
    list<id> liIds = new list<id>();
    
    for(Task sTask : trigger.new)
    {
        if(sTask.Status == 'Completed' && sTask.Subject == 'Call')
        {
            liIds.add(sTask.WhoId);
        }
    }
    
    for(Lead sLead : [select Id, Status from Lead where Id in : liIds])
    {
        sLead.Status = 'Contacted';
        liLeads.add(sLead);
    }
    
    update liLeads; 
    
}