From time to time, people on the Salesforce.com forums ask how they can make a Mass Case Close button that skips the Case Close screen and just closes the cases directly. This is just a twist on the Quick Case Close button that I have written about previously on this blog. The code is quite simple:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Case)};
if (records[0] == null) {
alert("Please select at least one case to close.")
} else {
//Get more info on the cases that were selected and generate a query out of it
var updateRecords = [];
//Iterate through the returned results
for (var recordIndex=0;recordIndex<records.length;recordIndex++) {
var caseUpdate = new sforce.SObject("Case");
caseUpdate.Id = records[recordIndex];
caseUpdate.Status = 'Closed';
updateRecords.push(caseUpdate);
}
var result = sforce.connection.update(updateRecords);
//handle errors here
if (result.error) {
alert('There was an error processing one or more cases');
}
//Reload the list view to show what he now owns
parent.window.location.reload();
}
To add this code, go to Setup->Cases->Buttons and Links and make a new custom button called Mass Close. Its Display Type should be set to List Button, its Behavior to Execute JavaScript, and its Content Source to OnClick JavaScript. Paste the above code into the OnClick JavaScript field -- but be sure to replace the caseUpdate.Status = 'Closed'; line with a status that is present in your org.
Now you'll have to add this button to the Case list view. To do this, go to Setup->Cases->Search Layouts. Click Edit next to the Cases List View entry, and add your new button from the Available Buttons section to the Selected Buttons section. As with the Contention-Proof Accept Button, the trick here is that GETRECORDIDS call -- it gets us the list of Case IDs that you selected from the list. The rest here is simple, just put all those Case IDs into an array and set the case status fields to Closed, and call update. Easy! Just imagine what other sorts of mass actions you could do with this method. It's hard to fathom the creativity of the readers of this blog.
Oh, wow. This was great! Did it in less than 5 minutes.
ReplyDelete