function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
3333 

Trigger to prevent event transfer when case owner changes

Hi all,

 

As it is, "When you change case ownership, any associated open activities that are owned by the current case owner are transferred to the new owner." I want to prevent the open activities reassignment by an apex trigger. however, it seems to not work at all. Here is my code:

 

trigger StopEventOwnerChange on Event (before update) {
List<Event> updateEvent = new List<Event>();
for(Event e:trigger.new){
if(e.ownerId != e.CreatedById)
updateEvent.add(e);
}
for(Event e:updateEvent){
e.ownerId = e.CreatedById;
}
}

 

Andy BoettcherAndy Boettcher

The SF process that is changing the Event ownership is firing after your triggers do - which is why it's not working.  

Andy BoettcherAndy Boettcher

Not necessarily solving your direct issue, but you could create a custom field on the Event object that could be populated with the Event owner after the Event is created (workflow / field update on creation) - that would stay static through any Ownership change and may be something that your users can reference?

 

-Andy