+ Start a Discussion

Override the delete button on Account


Need to override the delete button on Account object such that the user is not able to edit the Account record if it has any Opportunity ot Service Agreement or Equipment record attached to it.
I have got two record types in Accounts named Customer Account and Sit Account. One should not not be able to delet the Customer Account if the Site Account attacjed to it has any Service Agreement or Equipment or Opportunity attached to it.

Hi ,

Check if you can write a Validation rule with  the criteria of attachment.

If attachment != null etc - throw error.

Also See the links below, 



I don't think using validation rule this is possible. I am just preventing users from deleting records based upon some criterias . I do not want them to be completely prevented from deleting Account records.
Saravanan @CreationSaravanan @Creation

I took the asumtion of override means you have to redirect to different page based on your condition.
To achive this you have to create custom to execute javascript.In the java script you need to use ajax call to get the records and check you condition.

Refer the below post:
Mikola SenykMikola Senyk
Hi Wik,

You can override Delete action on the Account object. But first you have to create custom visualforce page with standard conroller equals to Account and controller extension.
Example of standard controller extension:
public with sharing class CustomDelAccountContExt {

    public Account a;
    public CustomDelAccountContExt(ApexPages.StandardController stdController) {
        a = (Account) stdController.getRecord();
    public PageReference checkForDelete() {
        // TODO logic

        return null;
Example of visualforce page:
<apex:page standardController="Account" extensions="CustomDelAccountContExt" action="{!checkForDelete}">
    <apex:outputLabel >Delete account: {!Account.Name}</apex:outputLabel>
After that you can associate custom visualforce page and 'Delete' action of Account. Use the following path:
Setup / Customize / Account / Buttons, Links, and Actions
Press Edit link related to 'Delete' action.
The dialog will be similar to the next picture:
Override Delete action for Account
Now you can put whole custom logic inside checkForDelete() method of controller CustomDelAccountContExt.

However, I would prefer method that was suggested by Ashish_SFDC. I mean using of Validation rules. It will be much easier and more clear.
The simplest way, I think is to write a trigger before delete. In this trigger based on your criteria you may add error to the record and prevent it from deleting or let it go and delete the record if the criteria is not met.