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
2 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 2 hours ago
Json Bourne Shell
9211
9211
2
What have you done so far?
– Carlos Naranjo
2 hours ago
add a comment |
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
add a comment |
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.
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
add a comment |
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;
}
}
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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 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
add a comment |
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
add a comment |
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;
}
}
add a comment |
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;
}
}
add a comment |
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;
}
}
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 1 hour ago
Pranay Jaiswal
11.1k31951
11.1k31951
add a comment |
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
2 hours ago