+ Start a Discussion
lukas.wallisch1.3903815994810598E12lukas.wallisch1.3903815994810598E12 

System.AssertException: Assertion Failed

Hello,

I am about to deploy my first trigger to production. When I ran a test in the sandbox I got 100% code coverage, in production I got failed assertion unfortunately.

Here's my trigger for cloning the StartDateTime field from the event to a custom field to use it to calculate days with it:

trigger Eventdate on Event (before insert, before update) {
    for(Event e : trigger.new){
        // write custom field "Start Date/Time"
        e.Start_Date_Time__c = e.StartDateTime;
    }
}


My test class looks like this:

@isTest
// test for the 'Eventdate' triggers
private class Eventdate {
    static testMethod void test() {
        // create dummy Event
        Event e = new Event(ActivityDateTime=Date.Today(), Description='Test Event',
                            DurationInMinutes=10, Subject='Test Event', z_Thema__c='privat');

        insert e;

        // get the custom "Start Date/Time" field values
        DateTime dtmStart_e = [SELECT Start_Date_Time__c FROM Event WHERE
                               Id = :e.Id LIMIT 1].Start_Date_Time__c;

        // test "Start Date/Time"
        System.assert(dtmStart_e == e.StartDateTime);
    }
}


Failure Message: "System.AssertException: Assertion Failed", Failure Stack Trace: "Class.Eventdate.test: line 16, column 1"


I really have no clue what I'm doing wrong so I'm looking forward to any help.

Thank you!
Best Answer chosen by lukas.wallisch1.3903815994810598E12
Vinita_SFDCVinita_SFDC
Hello,

When you insert event e, you get the ID back automatically, but you don't get any other field changes, so Start_Date_Time__c will be empty. So insert some value for Start_Date_Time__c and then test. You can also check system.debug statements to check values.

All Answers

Vinita_SFDCVinita_SFDC
Hello,

When you insert event e, you get the ID back automatically, but you don't get any other field changes, so Start_Date_Time__c will be empty. So insert some value for Start_Date_Time__c and then test. You can also check system.debug statements to check values.
This was selected as the best answer
lukas.wallisch1.3903815994810598E12lukas.wallisch1.3903815994810598E12
Hi Vinita,

you're amazing! I inserted a date for StartDateTime and now it works perfectly!

Event e = new Event(StartDateTime=Date.Today(),ActivityDateTime=Date.Today(), Description='Test Event',
                            DurationInMinutes=10, Subject='Test Event', z_Thema__c='privat');

Thanks so much!