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__cCheckbox : eventcancelled__ctrigger : 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 you5 respuestas
Hi Ronu,Updated code:
If it helps mark it as best answer.Thanks!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 && oldItems.get(currentEvent.Id).GAM_MeetingCancelled__c ==true && currentEvent.GAM_MeetingCancelled__c == false )){ if (currentEvent.Subject.contains('CANCELLED -'))
{
currentEvent.Subject = currentEvent.Subject.substringAfter('CANCELLED -') ;
} }
}
}