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
    5 hours ago










  • @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
    9 secs 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
    5 hours ago










  • @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
    9 secs 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 5 hours ago









Json Bourne Shell

9411




9411








  • 2




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










  • @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
    9 secs ago














  • 2




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










  • @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
    9 secs ago








2




2




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




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












@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
9 secs ago




@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
9 secs ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










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


















up vote
5
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
    5 hours 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
    5 hours 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
    5 hours ago










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    2 mins ago











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
3
down vote



accepted










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















up vote
3
down vote



accepted










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













up vote
3
down vote



accepted







up vote
3
down vote



accepted






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 5 hours ago









Pranay Jaiswal

11.2k31951




11.2k31951












  • thank you for the response. I will update here in case of issues.
    – Json Bourne Shell
    1 min ago


















  • thank you for the response. I will update here in case of issues.
    – Json Bourne Shell
    1 min ago
















thank you for the response. I will update here in case of issues.
– Json Bourne Shell
1 min ago




thank you for the response. I will update here in case of issues.
– Json Bourne Shell
1 min ago












up vote
5
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
    5 hours 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
    5 hours 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
    5 hours ago










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    2 mins ago















up vote
5
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
    5 hours 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
    5 hours 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
    5 hours ago










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    2 mins ago













up vote
5
down vote










up vote
5
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 5 hours ago









David Reed

26.4k51645




26.4k51645












  • Why not let the event delete and then undelete it in future method?
    – Pranay Jaiswal
    5 hours 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
    5 hours 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
    5 hours ago










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    2 mins ago


















  • Why not let the event delete and then undelete it in future method?
    – Pranay Jaiswal
    5 hours 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
    5 hours 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
    5 hours ago










  • @DavidReed Thank you for the response.
    – Json Bourne Shell
    2 mins ago
















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




Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
5 hours 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
5 hours 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
5 hours 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
5 hours 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
5 hours ago












@DavidReed Thank you for the response.
– Json Bourne Shell
2 mins ago




@DavidReed Thank you for the response.
– Json Bourne Shell
2 mins ago


















 

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

數位音樂下載

格利澤436b

When can things happen in Etherscan, such as the picture below?