• Luke Debrita
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello,

I have created the below trigger from events to write certain information to leads if event type criterea met:

1
2
3
4
5
6
7
8
9
10
11
12
13
trigger LeadUpdates on Event (before insert) {
  Set<Id> recordIds = new Set<Id>();
  List<Lead> leadsToUpdate = new List<Lead>();
      for(Event t:Trigger.new)
        if(t.type=='Discovery')
          recordIds.add(t.whoid);
      leadsToUpdate = [select id from lead where id in :recordIds];
          for(Lead l:leadsToUpdate)
            {L.SQL_Scheduled__c = TRUE;
             L.Status = '07 SQL';
             }
            update leadsToUpdate;
}

Here is the test class I wrote.  What am I missing?  When I validate the depoyment I get an error that there is 0% coverage for my trigger:


@isTest
public class testEventTrigger {
  static testMethod void test1() {
        // set up leads
        List<Lead> testLeads = new List<Lead>();
        Lead lead1 = new Lead();
        lead1.Company = 'Test 1 New Company';
        lead1.LastName = 'Martha';
        lead1.LeadSource = 'Not Converted';
        lead1.Status = '04 Sales Lead';
        lead1.Email = 'test@test.com';
        lead1.Business_Type__c = 'App/Business';
        lead1.Lead_Role__c = 'Product';
        testLeads.add(lead1);
        
        Lead lead2 = new Lead();
        lead2.Company = 'Test 12';
        lead2.LastName = 'Jordan';
        lead2.LeadSource = 'Not Converted';
        lead2.Status = '04 Sales Lead';
        lead2.Email = 'test@test.com';
        lead2.Business_Type__c = 'App/Business';
        lead2.Lead_Role__c = 'Product';
        testLeads.add(lead2);
    insert testLeads;
    
        // set up Events
       List<Event> events = new List<Event>();
       Event event1 = new Event();
       event1.WhoId=testLeads[0].Id; 
       event1.Subject= 'Test0';
       event1.Type='Discovery';
       event1.STARTDATETIME=System.today();
       event1.ENDDATETIME=System.today();

       Event event2 = new Event();
       event2.WhoId=testLeads[1].Id; 
       event2.Subject= 'Test1';
       event2.Type='Discovery';
       event2.STARTDATETIME=System.today();
       event2.ENDDATETIME=System.today();
    
    insert events;
    
    Map<Id,Lead> leadResults1 = new Map<Id,Lead>([select id,SQL_Scheduled__c from lead where id in :testLeads]);
    System.assertEquals(testLeads[1].SQL_Scheduled__c,leadResults1.get(testLeads[1].Id).SQL_Scheduled__c,TRUE);
    System.assertEquals(testLeads[0].SQL_Scheduled__c,leadResults1.get(testLeads[0].id).SQL_Scheduled__c,TRUE);
    
    Map<Id,Lead> leadResults2 = new Map<Id,Lead>([select id,Status from lead where id in :testLeads]);
    System.assertEquals(testLeads[1].Status,leadResults2.get(testLeads[1].Id).Status,'07 SQL');
    System.assertEquals(testLeads[0].Status,leadResults2.get(testLeads[0].id).Status,'07 SQL');
  }}
Hello,

I have created the below trigger from events to write certain information to leads if event type criterea met:

1
2
3
4
5
6
7
8
9
10
11
12
13
trigger LeadUpdates on Event (before insert) {
  Set<Id> recordIds = new Set<Id>();
  List<Lead> leadsToUpdate = new List<Lead>();
      for(Event t:Trigger.new)
        if(t.type=='Discovery')
          recordIds.add(t.whoid);
      leadsToUpdate = [select id from lead where id in :recordIds];
          for(Lead l:leadsToUpdate)
            {L.SQL_Scheduled__c = TRUE;
             L.Status = '07 SQL';
             }
            update leadsToUpdate;
}

Here is the test class I wrote.  What am I missing?  When I validate the depoyment I get an error that there is 0% coverage for my trigger:


@isTest
public class testEventTrigger {
  static testMethod void test1() {
        // set up leads
        List<Lead> testLeads = new List<Lead>();
        Lead lead1 = new Lead();
        lead1.Company = 'Test 1 New Company';
        lead1.LastName = 'Martha';
        lead1.LeadSource = 'Not Converted';
        lead1.Status = '04 Sales Lead';
        lead1.Email = 'test@test.com';
        lead1.Business_Type__c = 'App/Business';
        lead1.Lead_Role__c = 'Product';
        testLeads.add(lead1);
        
        Lead lead2 = new Lead();
        lead2.Company = 'Test 12';
        lead2.LastName = 'Jordan';
        lead2.LeadSource = 'Not Converted';
        lead2.Status = '04 Sales Lead';
        lead2.Email = 'test@test.com';
        lead2.Business_Type__c = 'App/Business';
        lead2.Lead_Role__c = 'Product';
        testLeads.add(lead2);
    insert testLeads;
    
        // set up Events
       List<Event> events = new List<Event>();
       Event event1 = new Event();
       event1.WhoId=testLeads[0].Id; 
       event1.Subject= 'Test0';
       event1.Type='Discovery';
       event1.STARTDATETIME=System.today();
       event1.ENDDATETIME=System.today();

       Event event2 = new Event();
       event2.WhoId=testLeads[1].Id; 
       event2.Subject= 'Test1';
       event2.Type='Discovery';
       event2.STARTDATETIME=System.today();
       event2.ENDDATETIME=System.today();
    
    insert events;
    
    Map<Id,Lead> leadResults1 = new Map<Id,Lead>([select id,SQL_Scheduled__c from lead where id in :testLeads]);
    System.assertEquals(testLeads[1].SQL_Scheduled__c,leadResults1.get(testLeads[1].Id).SQL_Scheduled__c,TRUE);
    System.assertEquals(testLeads[0].SQL_Scheduled__c,leadResults1.get(testLeads[0].id).SQL_Scheduled__c,TRUE);
    
    Map<Id,Lead> leadResults2 = new Map<Id,Lead>([select id,Status from lead where id in :testLeads]);
    System.assertEquals(testLeads[1].Status,leadResults2.get(testLeads[1].Id).Status,'07 SQL');
    System.assertEquals(testLeads[0].Status,leadResults2.get(testLeads[0].id).Status,'07 SQL');
  }}