You need to sign in to do that
Don't have an account?
Andrew Hoban 6
Multiple IF statements in a trigger
Hi all,
I was wondering if its possible for multiple if statements to fire independantly inside one trigger. I wish to see if a checkbok is either true or false, the date and time field gets populated with the current time and date. This works if im doing one if statement, the trouble begins when i create a similar if statement below. The trigger will populate both the date and time fields instead of just one. I am trying to avoid creating multiple triggers and instead having one. The code is as follows:
I have tried doing this without the else however the same problem occurs. Thank you.
I was wondering if its possible for multiple if statements to fire independantly inside one trigger. I wish to see if a checkbok is either true or false, the date and time field gets populated with the current time and date. This works if im doing one if statement, the trouble begins when i create a similar if statement below. The trigger will populate both the date and time fields instead of just one. I am trying to avoid creating multiple triggers and instead having one. The code is as follows:
trigger checkedTimeTriggers on Match_Day_Check_List__c (before insert, before update) { for(match_day_check_list__c t: trigger.new){ if(t.Handshake_Event_Setup__c == True || t.Handshake_Event_Setup__c == False) { t.Handshake_Event_Setup_Checked_At__c = DateTime.Now(); } Else{ if(t.Access_Manager_Checks__c == True || t.Access_Manager_Checks__c == False) { t.Access_Manager_Checks_Checked_At__c = DateTime.Now(); } } } }
I have tried doing this without the else however the same problem occurs. Thank you.
Please refer below updated code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
Hi,
For both the condition your are populating field with current dat and time.
Even if it is true or false you want to populate field with current date and time than you simply update the field.
For this refer below code:
This works perfectly, however I should have mentioned that I only want the date/time field to update if that particular checkbox has been modified. With this code if anything is checked all of the times change. I am trying to simulate a field last modifed feature. I hope this makes sence.
Please refer below updated code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal