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
Ollie BatchelorOllie Batchelor 

Case Delete Custom Button

Hi all,

Is there a way to create a custom button to link directly to the salesforce standard page for deleting a case? I'm unable to add the standard button to the case detail page on a feed view so we have to go to a different view on the case to delete it.

Alternatively is there a standard code for deleting a case
Best Answer chosen by Ollie Batchelor
Arvind KumarArvind Kumar
Hi Ollie,

Use below code, with this help you can delete your case.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 


var cs = new sforce.SObject("Case"); 
cs.id = '{!Case.Id}'; 

alert ('id is ' + [cs.id]); 

var result = sforce.connection.deleteIds([cs.id]); 

if(result[0].getBoolean("success")) { 
alert('Case has been deleted successfully'); 
window.location.reload(); 
} 
else{ 
alert('Error : '+result); 
}


If you have nay issue, please let me know.

Thanks,

Arvind Kumar

All Answers

Arvind KumarArvind Kumar
Hi Ollie,

Use below code, with this help you can delete your case.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 


var cs = new sforce.SObject("Case"); 
cs.id = '{!Case.Id}'; 

alert ('id is ' + [cs.id]); 

var result = sforce.connection.deleteIds([cs.id]); 

if(result[0].getBoolean("success")) { 
alert('Case has been deleted successfully'); 
window.location.reload(); 
} 
else{ 
alert('Error : '+result); 
}


If you have nay issue, please let me know.

Thanks,

Arvind Kumar

This was selected as the best answer
Arvind KumarArvind Kumar

Hi,

Follow the below steps for create new custom button.
1.) Go to Setup | Case
2.) Click on the Name of the Case
3.) Click on the Buttons, Links & Actions section.
4.) Click on New Button or Link
5.) Name it as Case Delete
6.) Select the Display Type: Detail Page Button
7.) Behaviour: Execute JavaScript
8.) Content Source: OnClick JavaScript
9.) Paste above mention code.
10.) Save.
11.) Put custom button on page.

Thanks,
Arvind Kumar

Ollie BatchelorOllie Batchelor
Thank you the code works great! 
Arvind KumarArvind Kumar
Hi Ollie,

Please mark as a best answer. If it solves your problem.

You can contact me, I will help you any time.

Thanks,
Arvind Kumar