You need to sign in to do that
Don't have an account?
Trigger to update subject on checkbox update
Hi Experts
I need quick help on one of the trigger i have written. I have a trigger on event object and what it does is updating a subject field with "Cencelled" word in front of the subject when one checkbox is checked.
Subject field : Subject__c
Checkbox : eventcancelled__c
trigger : public static void updateSubjectOnActivity(List<Event> newItems , Map<Id,Event> oldItems) { for(Event currentEvent : newItems){
if( (oldItems != null && currentEvent.GAM_MeetingCancelled__c != oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c && currentEvent.GAM_MeetingCancelled__c == true )){
currentEvent.Subject = 'CANCELLED' + ' - ' + currentEvent.Subject;
}
if( (oldItems != null && currentEvent.GAM_MeetingCancelled__c != oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c && currentEvent.GAM_MeetingCancelled__c == false )){
currentEvent.Subject = currentEvent.Subject ;
}
}
}
This is working fine for me. Now i want to remove the "Cancelled" word from subject when again checkbox is unchecked. Not sure how should i take the first oldest value again in my map.
Please help and thanks in advance..!!
Thank you
Updated code:
If it helps mark it as best answer.
Thanks!
All Answers
Updated code:
If it helps mark it as best answer.
Thanks!
Thank you for your revert.
I changed my second IF condition which is :
if( (oldItems != null && currentEvent.GAM_MeetingCancelled__c != oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c && currentEvent.GAM_MeetingCancelled__c == false )){ currentEvent.Subject = currentEvent.Subject ; }
to yours condition :
if( (oldItems != null && oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c ==true && currentEvent.GAM_MeetingCancelled__c == false )){ currentEvent.Subject = currentEvent.Subject ; } }
Unfortunately nothing happened. Cancelled word is still there when I uncheck the checkbox.
Thanks..!!
for(Event currentEvent : newItems){
if( (oldItems != null && currentEvent.GAM_MeetingCancelled__c != oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c && currentEvent.GAM_MeetingCancelled__c == true )){
currentEvent.Subject = 'CANCELLED' + ' - ' + currentEvent.Subject;
}
if( (oldItems != null && currentEvent.GAM_MeetingCancelled__c != oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c && currentEvent.GAM_MeetingCancelled__c == false )){
currentEvent.Subject = currentEvent.Subject ;
}
}
}
In the above code, BOLD code is for adding the CANCELLED which is working fine. And rest of the code is where I am facing problem to remove the CANCELLED word from the subject. Hope this will help you..!!