• Hannah Butcher
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I am struggling to write the test class for a trigger that updates a custom lead field (date_demo_scheduled_for__c) based on the ActivityDate when an event is created. The following is the apex trigger which works in the sandbox and below that is what I have for the test class. Any insight would be greatly appreciated! I am a total newbie with apex currently.
TRIGGER:

Trigger DemoEvent on Event (after insert,after update) {
Event[] eventList;
eventList = trigger.new;
for (Event e:eventList) {
String leadId = e.WhoId;
if (e.WhoId!=null) {
Lead l = [SELECT Date_Demo_Scheduled_For__c FROM Lead WHERE Id = :leadId]; {
l.Date_Demo_Scheduled_For__c = e.ActivityDate;
} update l;
}
}
}

TEST CLASS:
@isTest
private class DemoEventTest {
    static testMethod void leadFix() {
       Lead b = new Lead (Name= 'DemoEventTest', Company='Grow.com', Date_Demo_Scheduled_For__c= '2016-11-02', Date_Demo_Given__c= '2016-10-15', Source__c='LinkedIn', Medium__c='Mined Sales', Campaign__c='No Data', Request__c='No Data');
       // Insert Lead
       insert b;
      // Insert Event
      Event evnt = new Event( Name = 'Test Event', ActivityDate = '2016-10-31');
                        insert event;
       // Retrieve the new Lead
       b = [SELECT Date_Demo_Scheduled_For__c FROM Lead WHERE Id =:b.Id];
       // Test that the trigger correctly updated the date demo scheduled for
    }
}
I did a change set from the sandbox to production and got the test to work for everything but the apex trigger. I get a 60% coverage message for the error. I am having a really tough time figuring out why it isn't working. It seems like this is a pretty common problem, but I can't get an easy answer for why that would happen. Anyone experienced this before?
I am struggling to write the test class for a trigger that updates a custom lead field (date_demo_scheduled_for__c) based on the ActivityDate when an event is created. The following is the apex trigger which works in the sandbox and below that is what I have for the test class. Any insight would be greatly appreciated! I am a total newbie with apex currently.
TRIGGER:

Trigger DemoEvent on Event (after insert,after update) {
Event[] eventList;
eventList = trigger.new;
for (Event e:eventList) {
String leadId = e.WhoId;
if (e.WhoId!=null) {
Lead l = [SELECT Date_Demo_Scheduled_For__c FROM Lead WHERE Id = :leadId]; {
l.Date_Demo_Scheduled_For__c = e.ActivityDate;
} update l;
}
}
}

TEST CLASS:
@isTest
private class DemoEventTest {
    static testMethod void leadFix() {
       Lead b = new Lead (Name= 'DemoEventTest', Company='Grow.com', Date_Demo_Scheduled_For__c= '2016-11-02', Date_Demo_Given__c= '2016-10-15', Source__c='LinkedIn', Medium__c='Mined Sales', Campaign__c='No Data', Request__c='No Data');
       // Insert Lead
       insert b;
      // Insert Event
      Event evnt = new Event( Name = 'Test Event', ActivityDate = '2016-10-31');
                        insert event;
       // Retrieve the new Lead
       b = [SELECT Date_Demo_Scheduled_For__c FROM Lead WHERE Id =:b.Id];
       // Test that the trigger correctly updated the date demo scheduled for
    }
}
Hi All,
I have a scenario where i need to send email to multiple contacts.

Under account contact we seperate some conact with type - 'Approvers' and one account can have multiple contacts with type Approvers.
When a oppty status is changed to status 'Need Review' an email should be sent to all account contacts with type approvers.

How can we configure this?