You need to sign in to do that
Don't have an account?
SFDC Guest
Test class for event object
Hi All,
Please help me to write test class for below class. I have wrote test class but it's not covering.
Test class:
Thanks
Please help me to write test class for below class. I have wrote test class but it's not covering.
public class eventClass{ // Method to validate start and End Time on events public static void ValidateStartEndTime(List<Event> evts) { for(Event ev: evts) { if(ev.StartDateTime.time() < Time.newInstance(7, 30, 0, 0)) { ev.StartDateTime.addError('Start time should be greater than or equals to 7:30 AM'); } if(ev.EndDateTime.time() > Time.newInstance(18, 00, 0, 0)) { ev.EndDateTime.addError('End time should be less than or equals to 6 PM'); } } } }
Test class:
@isTest public class eventClass_Test { static testMethod void testMethod1(){ Event e = new Event(); e.StartDateTime = Datetime.newInstance(2019, 1, 1, 08, 30, 00); e.EndDateTime = Datetime.newInstance(2019, 1, 1, 17, 30, 00); e.Subject = 'Meeting'; insert e; List<Event> eventRecs = new List<Event>(); eventRecs.add(e); eventClass.ValidateStartEndTime(eventRecs); }
Thanks
Greetings to you!
You are not using correct values for StartDateTime and EndDateTime in your test class. You need to provide values according to the conditions given in business class. Use below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
You could also scare people by adding some asserts.
Regards
Andrew
Test class for event object. This test class is 100% code coverage.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com