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












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
















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














1












1








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 Nov 27 '18 at 20:29









Json Bourne ShellJson Bourne Shell

10911




10911








  • 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














  • 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








2




2




What have you done so far?
– Carlos Naranjo
Nov 27 '18 at 20:32




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




@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










2 Answers
2






active

oldest

votes


















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;

}
}





share|improve this answer





















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



















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.






share|improve this answer





















  • 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










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    Nov 28 '18 at 2:14











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',
autoActivateHeartbeat: false,
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









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;

}
}





share|improve this answer





















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
















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;

}
}





share|improve this answer





















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














3












3








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;

}
}





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 Nov 27 '18 at 21:02









Pranay JaiswalPranay Jaiswal

14k32351




14k32351












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


















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
















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




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













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.






share|improve this answer





















  • 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










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    Nov 28 '18 at 2:14
















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.






share|improve this answer





















  • 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










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    Nov 28 '18 at 2:14














5












5








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.






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 Nov 27 '18 at 20:38









David ReedDavid Reed

31.1k61746




31.1k61746












  • 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










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    Nov 28 '18 at 2:14


















  • 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










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    Nov 28 '18 at 2:14
















Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
Nov 27 '18 at 21:03




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




@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




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




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












@DavidReed Thank you for the response.
– Json Bourne Shell
Nov 28 '18 at 2:14




@DavidReed Thank you for the response.
– Json Bourne Shell
Nov 28 '18 at 2:14


















draft saved

draft discarded




















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

Plaza Victoria

Puebla de Zaragoza

Musa