This is a long shot, as I've already gone a fair bit of googling, but wanted to check with the Stack community to cover all my bases.

Scenario: Our reps sometimes have to 'Cancel' events and remove them from their Calendar, and sometimes other users (front desk) need to cancel events for anyone in the business, on behalf of the customer if they call to cancel.

We also want to track Cancellation History for each account, and allow for people to cancel for one another - so we can't use the normal delete button due to Role Hierarchy security getting in the way of people deleting for other people.

So, I built an Apex trigger and class method that checks to see when the status of an Event is first set to "Cancelled" (after update), and then it copies/inserts all relevant Event data into a custom object called Cancellation_History__c and deletes the Event that was just marked as "Cancelled".

Problem/Question: When a user edits the Event record and marks it as "Cancelled", obviously that triggers the Apex which, in turn, deletes the Event record that was just modified. Since the user just saved/updated that record, Salesforce standard behavior wants to redirect them to the record that they just updated. However, Apex has already deleted that record, which results in the user reaching the "Record Deleted" page.

Can I somehow improve this user experience, by rerouting them programmatically to the account page instead of the standard behavior of trying to load the record that was just deleted?

I'm happy to provide code if requested, but I don't think it is relevant to the question itself so I excluded it. We currently use standard Salesforce page layouts (not VisualForce pages), but if there is a solution that exists through VisualForce I'd be happy to hear it also.

Thanks for your time!

  • Did you ever try any of the recommended strategies?
    – Adrian Larson
    Commented Jun 14, 2016 at 15:31
  • Hey @AdrianLarson, sorry for the delay - I haven't yet tried actually. I was in the Salesforce DEV450 training class all last week so I haven't had a chance. I like your solution tho, it looks elegant. I'll test it today or tomorrow and let you know how it goes. Commented Jun 14, 2016 at 18:39
  • Don't forget, if you think the answer is useful, even if you do not adopt the recommended approach, you can vote for it. :) Up-votes don't commit you to accept the answer or follow through with the recommendation therein.
    – Adrian Larson
    Commented Jun 14, 2016 at 19:40

2 Answers 2


Another option is to override the View action so that when you get a deleted record, you redirect to the home page, otherwise, go to the normal detail page. This approach may be less intrusive to your users' workflow than having a separate edit process when they wish to cancel.


    action="{!redirect}" />


public with sharing class EventViewExtension
    final Id recordId;
    final PageReference view;
    public EventViewExtension(ApexPages.StandardController controller)
        recordId = controller.getId();
        view = controller.view();
        view.getParameters().put('nooverride', '1');
    public PageReference redirect()
        List<Event> records = [
            SELECT IsDeleted, AccountId FROM Event
            WHERE Id = :recordId ALL ROWS

        if (records.isEmpty()) return new PageReference('/');

        if (!records[0].IsDeleted) return view;

        return new ApexPages.StandardController(
            new Account(Id=records[0].AccountId)
  • This worked perfectly Adrian, thank you for taking the time! Commented Jun 17, 2016 at 14:12

Write a Visualforce page for this. Without getting too intensive, it might look like this:

<apex:page standardController="Event" extensions="EventCancelExtension">
        <apex:commandButton action="{!cancelEvent}" value="Cancel" />

The extension you need would look like:

public class EventCancelExtension {
    ApexPages.StandardController controller;
    public EventCancelExtension(ApexPages.StandardController c) {
        controller = c;
    public PageReference cancelEvent() {
        // Do whatever you do here, then:
        return new ApexPages.StandardController(
            new Account(Id=((Event)c.getRecord()).AccountId)).view();

Feel free to include error handling, a better UX, and so on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .