1

Our Salesforce users are deleting Events from Salesforce due to our integration with Outlook. When a Meeting from Outlook is deleted, we want the corresponding Event record in Salesforce to be not deleted but change the status field (a custom field on Activity) to be marked as "Cancelled" instead. Is it possible to not delete the Event from delete trigger?

  • 2
    What have you done so far? – Carlos Naranjo Nov 27 '18 at 20:32
  • @CarlosNaranjo I didnt know where to start. Only thing I knew was, I can't stop a DML to happen which initiated the trigger. Hence, the question. – Json Bourne Shell Nov 28 '18 at 2:16
5

You cannot convert the delete event into an update. Once the DML operation has been started, you can block it (and potentially roll back the transaction) by adding an error on the record. That's unlikely to be what you want to do here.

Instead, I'd suggest you build your delete trigger to create a new Event (or Task), copying fields from the deleted recording and applying the transformation you mention to mark the event as cancelled. You can insert new Event records from the delete trigger.

  • Why not let the event delete and then undelete it in future method? – Pranay Jaiswal Nov 27 '18 at 21:03
  • @PranayJaiswal (1) I didn't think of it (clever idea!); (2) do you need to worry about bulk data processes that would blow out the Recycle Bin storage? – David Reed Nov 27 '18 at 21:04
  • 2
    If deleting from outlook its still one delete at a time, even its bulk, the trigger handles it. The only blocker is, if its cascade delete , then delete triggers are not fired. – Pranay Jaiswal Nov 27 '18 at 21:06
3

Yes you can do it using future / queuable APEX.

In the before delete trigger call the Future method which will undelete your event.

trigger EventTrigger on Event (before delete) {

    MyEventUndeleterFutureClass.undeletEvent(JSON.serialize(Trigger.old)); 
}

Then future class

public class MyEventUnDeleterFutureClass {
   @Future
    public static void undeletEvent(String eventJson){
        List<Event> EventList =(List<Event> ) JSON.deserialize(eventJson, List<Event> .class);

        System.debug(EventList);
        undelete EventList;

        for(Event even : EventList ){
            even.subject = even.subject+'Cancelled'; 
        }

        Update EventList;

    }
}
  • thank you for the response. I will update here in case of issues. – Json Bourne Shell Nov 28 '18 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.