You need to sign in to do that
Don't have an account?
BroncoBoy
Task Trigger: Reset Checkboxes to Unchecked, Retain Checkbox Values
I have a Task trigger on which I'm tyring to also reset the checkbox values to be unchecked in the before context but still use the initial values (prior to resetting) in the after context. The idea is to reset them without having to execute a DML update later on in the trigger. The problem is that the values are not being captured in the before context - they are all remaining false, so I can't use them for logic in the after context. Thank you in advance for any help you can provide.
Code:
trigger EmailTaskDescription on Task(before insert, after insert, before update, after update)
{
Boolean nofityRIW = false;
Boolean nofityREW = false;
Boolean nofityBDC = false;
Boolean nofityGIW = false;
Boolean nofityGEW = false;
if (trigger.isBefore)
{
Task tt = Trigger.new[0];
//capture checkbox selections
nofityRIW = tt.Notify_R_IW__c;
nofityREW = tt.Notify_R_EW__c;
nofityBDC = tt.Notify_BDC__c;
nofityGIW = tt.Notify_G_IW__c;
nofityGEW = tt.Notify_G_EW__c;
//reset checkbox selections to unchecked
tt.Notify_R_IW__c = false;
tt.Notify_R_EW__c = false;
tt.Notify_BDC__c = false;
tt.Notify_G_EW__c = false;
tt.Notify_G_IW__c = false;
}
if (trigger.isAfter)
{
//use initial values to execute logic
if (nofityRIW)
{
}
else if (nofityREW)
{
}
}
}
Code:
trigger EmailTaskDescription on Task(before insert, after insert, before update, after update)
{
Boolean nofityRIW = false;
Boolean nofityREW = false;
Boolean nofityBDC = false;
Boolean nofityGIW = false;
Boolean nofityGEW = false;
if (trigger.isBefore)
{
Task tt = Trigger.new[0];
//capture checkbox selections
nofityRIW = tt.Notify_R_IW__c;
nofityREW = tt.Notify_R_EW__c;
nofityBDC = tt.Notify_BDC__c;
nofityGIW = tt.Notify_G_IW__c;
nofityGEW = tt.Notify_G_EW__c;
//reset checkbox selections to unchecked
tt.Notify_R_IW__c = false;
tt.Notify_R_EW__c = false;
tt.Notify_BDC__c = false;
tt.Notify_G_EW__c = false;
tt.Notify_G_IW__c = false;
}
if (trigger.isAfter)
{
//use initial values to execute logic
if (nofityRIW)
{
}
else if (nofityREW)
{
}
}
}
In order to achieve this you have to create a class with static varibales.
So please create a new Class with Name = "SaveResults" and paste below code in it :
Now change your trigger code as follows :
Please modify your code as suggested above.
Let me know if you have any issue in it.
Thanks,
Abhishek
All Answers
In order to achieve this you have to create a class with static varibales.
So please create a new Class with Name = "SaveResults" and paste below code in it :
Now change your trigger code as follows :
Please modify your code as suggested above.
Let me know if you have any issue in it.
Thanks,
Abhishek
Try something like this.
Regards,
Sanpreet
Thanks again!
Bronco