You need to sign in to do that
Don't have an account?
Andrew Hoban 6
Test Class For Trigger
Hi all,
I am having difficulty creating a test class for a trigger I have created. The trigger updates a date/time field every fime a checkbox field is modified. I am unsure how i would create the tesst trigger, any help would be great.
My trigger is:
Many thanks.
I am having difficulty creating a test class for a trigger I have created. The trigger updates a date/time field every fime a checkbox field is modified. I am unsure how i would create the tesst trigger, any help would be great.
My trigger is:
trigger ControlRoomCheckedTimeTrigger on Match_Day_Check_List__c (before insert, before update) { if(Trigger.isInsert){ for(match_day_check_list__c b: trigger.new){ b.Steward_Phone_Check_Complete_Last_Mod__c = DateTime.Now(); b.Radio_Check_Complete_Last_Modified__c = DateTime.Now(); b.CCTV_Cameras_Checked_Last_Modified__c = DateTime.Now(); } } if(Trigger.isUpdate){ for(match_day_check_list__c b: trigger.new){ match_day_check_list__c oldb = Trigger.oldMap.get(b.ID); if(oldb.Steward_Phone_Check_Complete__c != b.Steward_Phone_Check_Complete__c){ b.Steward_Phone_Check_Complete_Last_Mod__c = DateTime.Now(); } if(oldb.Radio_Check_Complete__c != b.Radio_Check_Complete__c){ b.Radio_Check_Complete_Last_Modified__c = DateTime.Now(); } if(oldb.CCTV_Cameras_Checked__c != b.CCTV_Cameras_Checked__c){ b.CCTV_Cameras_Checked_Last_Modified__c = DateTime.Now(); } if(oldb.Turnstile_Checks_Control_Room__c != b.Turnstile_Checks_Control_Room__c){ b.Turnstile_Checks_Last_Modified_CRoom__c = DateTime.Now(); } } } }
Many thanks.
Try the code below.
I am assuming the name of those objects are fixture__c and match_plan__c. If they are not, please update it in the code at line no 5 and 6
All Answers
Try the test class below. let me know in case of any issues.
If that solves your problem, please mark this as the best answer.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Fixture__c, Match_Plan__c]: [Fixture__c, Match_Plan__c]
Class.ControlRoomTest.testmethod1: line 5, column
I have now added these into the test class however i am still getting the same error?
Thanks
If that solves your problem, please like this post and mark it as the best answer.
Thanks
I think it is something simple I am not doing correctly. Thanks
Try the code below.
I am assuming the name of those objects are fixture__c and match_plan__c. If they are not, please update it in the code at line no 5 and 6
Please like the post, and mark it as the best answer if that solves your query.
Thanks,
Rohit