2

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
  • 2
    What have you done so far? Commented Nov 27, 2018 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. Commented Nov 28, 2018 at 2:16

2 Answers 2

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.

3
  • Why not let the event delete and then undelete it in future method? Commented Nov 27, 2018 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
    Commented Nov 27, 2018 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. Commented Nov 27, 2018 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;

    }
}
1
  • thank you for the response. I will update here in case of issues. Commented Nov 28, 2018 at 2:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .