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
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
add a comment |
up vote
1
down vote
favorite
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
2
What have you done so far?
– Carlos Naranjo
10 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
4 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
trigger delete
asked 10 hours ago
Json Bourne Shell
9411
9411
2
What have you done so far?
– Carlos Naranjo
10 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
4 hours ago
add a comment |
2
What have you done so far?
– Carlos Naranjo
10 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
4 hours ago
2
2
What have you done so far?
– Carlos Naranjo
10 hours ago
What have you done so far?
– Carlos Naranjo
10 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
4 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
4 hours ago
add a comment |
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;
}
}
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
add a comment |
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.
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
add a comment |
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;
}
}
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
add a comment |
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;
}
}
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
add a comment |
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;
}
}
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;
}
}
answered 10 hours ago
Pranay Jaiswal
11.2k31951
11.2k31951
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
add a comment |
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
thank you for the response. I will update here in case of issues.
– Json Bourne Shell
5 hours ago
add a comment |
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.
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
add a comment |
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.
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
add a comment |
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.
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.
answered 10 hours ago
David Reed
26.4k51645
26.4k51645
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
add a comment |
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 hours ago
Why not let the event delete and then undelete it in future method?
– Pranay Jaiswal
10 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
10 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
10 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
10 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
10 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
@DavidReed Thank you for the response.
– Json Bourne Shell
5 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
What have you done so far?
– Carlos Naranjo
10 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
4 hours ago