How prevent deletion in Event delete trigger and update a field instead





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
1
down vote

favorite
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?










share|improve this question


















  • 2




    What have you done so far?
    – Carlos Naranjo
    2 hours ago

















up vote
1
down vote

favorite
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?










share|improve this question


















  • 2




    What have you done so far?
    – Carlos Naranjo
    2 hours ago













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






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?










share|improve this question













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?







trigger delete






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Json Bourne Shell

9211




9211








  • 2




    What have you done so far?
    – Carlos Naranjo
    2 hours ago














  • 2




    What have you done so far?
    – Carlos Naranjo
    2 hours ago








2




2




What have you done so far?
– Carlos Naranjo
2 hours ago




What have you done so far?
– Carlos Naranjo
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
4
down vote













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.






share|improve this answer





















  • Why not let the event delete and then undelete it in future method?
    – Pranay Jaiswal
    1 hour ago










  • @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
    1 hour ago






  • 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
    1 hour ago


















up vote
2
down vote













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;

}
}





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "459"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240708%2fhow-prevent-deletion-in-event-delete-trigger-and-update-a-field-instead%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    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.






    share|improve this answer





















    • Why not let the event delete and then undelete it in future method?
      – Pranay Jaiswal
      1 hour ago










    • @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
      1 hour ago






    • 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
      1 hour ago















    up vote
    4
    down vote













    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.






    share|improve this answer





















    • Why not let the event delete and then undelete it in future method?
      – Pranay Jaiswal
      1 hour ago










    • @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
      1 hour ago






    • 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
      1 hour ago













    up vote
    4
    down vote










    up vote
    4
    down vote









    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.






    share|improve this answer












    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 1 hour ago









    David Reed

    26.4k51645




    26.4k51645












    • Why not let the event delete and then undelete it in future method?
      – Pranay Jaiswal
      1 hour ago










    • @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
      1 hour ago






    • 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
      1 hour ago


















    • Why not let the event delete and then undelete it in future method?
      – Pranay Jaiswal
      1 hour ago










    • @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
      1 hour ago






    • 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
      1 hour ago
















    Why not let the event delete and then undelete it in future method?
    – Pranay Jaiswal
    1 hour ago




    Why not let the event delete and then undelete it in future method?
    – Pranay Jaiswal
    1 hour ago












    @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
    1 hour ago




    @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
    1 hour ago




    2




    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
    1 hour ago




    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
    1 hour ago












    up vote
    2
    down vote













    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;

    }
    }





    share|improve this answer

























      up vote
      2
      down vote













      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;

      }
      }





      share|improve this answer























        up vote
        2
        down vote










        up vote
        2
        down vote









        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;

        }
        }





        share|improve this answer












        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;

        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Pranay Jaiswal

        11.1k31951




        11.1k31951






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240708%2fhow-prevent-deletion-in-event-delete-trigger-and-update-a-field-instead%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Willebadessen

            Ida-Boy-Ed-Garten

            Residenzschloss Arolsen