Kiva and the Quick Mass Close Button
Oct 2, 2008From time to time in my job as product manager of Service & Support I come into contact with people who are using Salesforce.com to make a difference in the world. One such company is Kiva.
Kiva is a microfinance non-profit that allows you to lend as little as $25 online to an entrepreneur in the developing world that needs a loan. On Kiva, you act as a banker to the poor by lending money to entrepreneurs in developing countries and then you get repaid. Amazingly, in just 3 years, they've lent $44 million to 92,000 entrepreneurs, with an astonishing 98.5% repayment rate.
Kiva is currently competing in the American Express Members Project, which will grant a grand prize of $1.5 million to the non-profit which garners the most votes from Amex cardmembers. This money at Kiva could enable $30 million more loans to fund 60,000 more entrepreneurs so that they can lift themselves out of poverty.
If you are an Amex cardmember, please click here to vote for Kiva – it really is a good cause.
And now on to the meat of today's post:
Kiva runs all of its customer service operations on Salesforce.com. A few weeks ago they came to me with a request which I've heard before: they wanted a Mass Case Close button that skips the Case Close screen and just closes the cases. This is just a twist on the Quick Case Close button that I have written about previously on this blog, so I was happy to oblige.
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.
And just in case you missed it: Vote for Kiva! :)

Hi Marco,
Maybe you can help - I want almost this same functionality, but for tasks. I would like to be able to go into a case and choose to mass close open activities. I would also LOVE to have it on the "Home" tab, but that is secondary.
Posted by: Rachel | July 31, 2009 at 06:21 PM