You need to sign in to do that
Don't have an account?
Nirmal Christopher
unable to update certain fields via trigger in events
In a scenario i want to retain only the old values of the event if the event is updated directly when related to a custom object. Here is my trigger. IT works fine for all the event fields except event start date and end date. These two field are not retaining their old values, It accepts the user Inputs.Also Debug statements working fine as expected. But its not updating the field values.
trigger prohibitUpdate on Event (before update) {
Set<id>neweveid=new set<id>();
Set<id>whatid=new set<id>();
for(event eve:trigger.new){
neweveid.add(eve.id);
whatid.add(eve.whatid);
}
for(event eve:trigger.new){
Event oldEve = Trigger.oldMap.get(eve.id);
if(trigger.isupdate){
system.debug('******'+trigger.old[0].StartDateTime);
eve.StartDateTime=oldEve.StartDateTime;
eve.EndDateTime=oldEve.EndDateTime;
eve.Onsite_Arrival_DateTime__c = oldEve.Onsite_Arrival_DateTime__c;
eve.Onsite_Completion_DateTime__c = oldEve.Onsite_Completion_DateTime__c;
eve.Location = oldEve.Location;
eve.Description = oldEve.Description;
eve.OwnerId = oldEve.OwnerId;
eve.ShowAs = 'OutofOffice';
eve.Subject = oldEve.Subject;
eve.WhoId = oldEve.WhoId;
}
}
}
trigger prohibitUpdate on Event (before update) {
Set<id>neweveid=new set<id>();
Set<id>whatid=new set<id>();
for(event eve:trigger.new){
neweveid.add(eve.id);
whatid.add(eve.whatid);
}
for(event eve:trigger.new){
Event oldEve = Trigger.oldMap.get(eve.id);
if(trigger.isupdate){
system.debug('******'+trigger.old[0].StartDateTime);
eve.StartDateTime=oldEve.StartDateTime;
eve.EndDateTime=oldEve.EndDateTime;
eve.Onsite_Arrival_DateTime__c = oldEve.Onsite_Arrival_DateTime__c;
eve.Onsite_Completion_DateTime__c = oldEve.Onsite_Completion_DateTime__c;
eve.Location = oldEve.Location;
eve.Description = oldEve.Description;
eve.OwnerId = oldEve.OwnerId;
eve.ShowAs = 'OutofOffice';
eve.Subject = oldEve.Subject;
eve.WhoId = oldEve.WhoId;
}
}
}
Two additional Event fields had to be overwritten:
newEve.ActivityDateTime = oldEve.ActivityDateTime ;
newEve.DurationInMinutes= oldEve.DurationInMinutes;
Apparently there is logic associating these fields with the new StartDateTime and EndDateTime fields. If there is an inconsistency, then the "old" values are rejected and the "new" values are used.
All Answers
Two additional Event fields had to be overwritten:
newEve.ActivityDateTime = oldEve.ActivityDateTime ;
newEve.DurationInMinutes= oldEve.DurationInMinutes;
Apparently there is logic associating these fields with the new StartDateTime and EndDateTime fields. If there is an inconsistency, then the "old" values are rejected and the "new" values are used.