function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
XXXXXX 

Override Delete Button Generically?

I am looking, as usual, for something that might not exist. What I want to do is create a generic VF page using a custom controller that I can call from a custom URL button.

 

I am specifically NOT using a standardController here, because I want to call this same page from layout for any object. Since I am not using a standardController, I cannot use a VF button, so I must therefore use a URL button.

 

Anyway, what I want to do is let my customer override the Delete button. When my customer clicks the Delete button, the current record is deleted AND my page checks for other things that need to be deleted and deletes them, too. Before you ask, I cannot use Apex triggers to do this.

 

So what I want to know is, how can I delete the current record considering that this button may be on ANY object?

 

TIA,

 

John

aalbertaalbert

First, in the URL that you configure for the button, pass in the record ID as a merge field into the url query string. That way, the controller will have the record ID. Secondly, you could use Dynamic Apex to generically determine what Object type the record ID belongs to. The key is to do a global describe all of objects in your environment and check the keyPrefix.