5

After deleting a record* SalesForce always seems to return to the main list. So if you delete a contact you end up at /003/o instead of at the account.

But it makes more sense in many cases to end up where you started which was typically the master record. Or, in cases where you have no master-detail relationship but just a lookup you want to guide the user back to the parent record.

What's the best way to send the user back to the parent record?

* UPDATE: From the detail page of the record being deleted

9

You do know you have it out of the box, just hit delete link on Contact related list when you're on Account?

... If you're talking about [Delete] on Contact detail - VF seems like a bit of overkill, why not simply a button (overridden delete action or hide standard delete button) that hand-crafts link similar to

https://na5.salesforce.com/setup/own/deleteredirect.jsp?
delID=0037000000Zi6Yl&
retURL=%2F0017000000R5W4W
| improve this answer | |
  • 3
    Yep, I mean from the detail page. I like this approach thanks! (I scream, you scream we all scream for eyescream!) – Marc Mar 1 '13 at 3:26
5

This is the way I would handle this requirement:

  • Create a new Visualforce page and with a controller extension that is on the object.
  • On that Visualforce page, all you need is an action specified on the <apex:page> tag. Something like:

    <apex:page standardController="Custom_Object__c" extensions="CustomObjectDeleteControllerExt" action="{!customDelete}">
    </apex:page>
    
  • This will allow you to override the Delete standard button. You will need to create your own customDelete action which would look like:

    public with sharing class CustomObjectDeleteControllerExt {
        private Custom_Object__c customObject;
    
        public CustomObjectDeleteControllerExt(ApexPages.StandardController stdController) {
            this.customObject = (Custom_Object__c)stdController.getRecord();
        }
    
        public PageReference customDelete(){
            delete customObject;
    
            // Return whatever PageReference you want here
            return new PageReference();
         }
    }
    

The way that will work is your page will load, hitting the constructor and populating the object to delete. You can't perform DML statements in a constructor, so you need your action on the page which is called immediately after the constructor. The action will perform, deleting the record, and then you can redirect to any record you want. By overriding the standard button, this will replace Delete functionality wherever a standard Delete button/link is used.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.