You need to sign in to do that
Don't have an account?
bikla78
Test method for trigger
All my test methods I have for events are failing is there a special way I need to write my test method since I am using the created date field for the business logic. It keeps saying 0% at least 1 line needs to be tested and i have several event test classess for my other triggers.Also all my other triggers call classes and this is the only one where the business logic is built inside the tirgger...do i have to create a new test method. if so, how do i call it from here
trigger Event_Before_Insert on Event (before update)
{
for( Event currentEvent : Trigger.new )
{
datetime CreatedDate =CurrentEvent.CreatedDate;
date ActivityDate =CurrentEvent.ActivityDate;
date createdDateTemp = date.newInstance(CreatedDate.year(),CreatedDate.month(),CreatedDate.day());
Integer numberofDays = createdDateTemp.daysBetween(ActivityDate);
CurrentEvent.Day_Count__c = numberofDays;
}
}
The other test methods are all insert tests but i have triggers that is before insert and update.Below is one of my methods. How do I convert this into an update statement
Event ev48 = new Event(Subject = 'Test', Type= 'Other', Meeting_Status__c = 'Pending',ActivityDate =Date.today(),WhoId = cont.Id );
try {
insert event;
}
catch(DmlException e) {
System.debug(e.getMessage());
}
This test never tests the update trigger because you never do an update to the event. You should take that event you just inserted and update it. Below is a simple example. Although ideally you would write the test method to actually use assertions to make sure your code is working properly ;)
Event ev48 = new Event(Subject = 'Test', Type= 'Other', Meeting_Status__c = 'Pending',ActivityDate =Date.today(),WhoId = cont.Id );
try {
insert event;
}
catch(DmlException e) {
System.debug(e.getMessage());
}
event.custom_field__c = "test";
update event;
I tried this but it is still saying zero percent.
Event ev48 = new Event(Subject = 'Test', Type= 'Other', Meeting_Status__c = 'Pending',ActivityDate =Date.today(),WhoId = cont.Id );
try {
insert ev48;
}
catch(DmlException e) {
System.debug(e.getMessage());
}
ev48.day_count__c =0;
update ev48;