In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click “Delete” button.
In this example, we will create a simple List View button and add on “Search Layout” of that object.
So, create a new Custom Button with following property:
- Display Type : List Button
- Behavior : Execute JavaScript
- Content Source : OnClick JavaScript
and use below Source code:
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")} //Below ObjectType can be replaced by anyObject. I have used "Test Name" var records = {!GETRECORDIDS($ObjectType.Test_Name__c)}; if (records[0] == null) { alert("Please select at least one record.") } else { var opt = confirm("Are you sure you want to delete selected records ?"); if (opt == true) { var errors = []; var result = sforce.connection.deleteIds(records); if (result && result.length) { var numFailed = 0; var numSucceeded = 0; for (var i = 0; i < result.length; i++) { var res = result[i]; if (res && res.success == 'true') { numSucceeded++; } else { var es = res.getArray("errors"); if (es.length > 0) { errors.push(es[0].message); } numFailed++; } } if (numFailed > 0) { alert("Failed: " + numFailed + "nSucceeded: " + numSucceeded + " n Due to: " + errors.join("n")); } else { alert("Number of records deleted: " + numSucceeded); } } window.location.reload(); } }
In above code, we only need to change line number 4 for Object Type.
Once you are done with above button, add button in Search Layout’s List View as shown in below Image.
Leave a Reply