{"id":3299,"date":"2013-05-06T21:01:05","date_gmt":"2013-05-06T15:31:05","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=3299"},"modified":"2014-09-12T18:55:00","modified_gmt":"2014-09-12T18:55:00","slug":"create-simple-mass-delete-button-for-listview-using-javascript","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/create-simple-mass-delete-button-for-listview-using-javascript\/","title":{"rendered":"Create Simple Mass Delete Button for ListView using Salesforce Ajax Toolkit"},"content":{"rendered":"<p>In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click &#8220;Delete&#8221; button.<\/p>\n<p>In this example, we will create a simple List View button and add on &#8220;Search Layout&#8221; of that object.<\/p>\n<figure id=\"attachment_3301\" aria-describedby=\"caption-attachment-3301\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Salesforce-Mass-Delete-Button-List-View.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3301\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Salesforce-Mass-Delete-Button-List-View.png?resize=594%2C211&#038;ssl=1\" alt=\"Salesforce Mass Delete Button - List View\" width=\"594\" height=\"211\" \/><\/a><figcaption id=\"caption-attachment-3301\" class=\"wp-caption-text\">Salesforce Mass Delete Button &#8211; List View<\/figcaption><\/figure>\n<p>So, create a new Custom Button with following property:<\/p>\n<ol>\n<li><strong>Display Type<\/strong>\u00a0: \u00a0List Button<\/li>\n<li><strong>Behavior<\/strong>\u00a0: Execute JavaScript<\/li>\n<li><strong>Content Source<\/strong>\u00a0: \u00a0OnClick JavaScript<\/li>\n<\/ol>\n<p>and use below Source code:<!--more--><\/p>\n<pre class=\"brush: java; highlight: [4]; title: ; notranslate\" title=\"\">\r\n{!REQUIRESCRIPT(&quot;\/soap\/ajax\/21.0\/connection.js&quot;)}\r\n\r\n\/\/Below ObjectType can be replaced by anyObject. I have used &quot;Test Name&quot;\r\nvar records = {!GETRECORDIDS($ObjectType.Test_Name__c)};\r\n\r\nif (records&#x5B;0] == null) {\r\n    alert(&quot;Please select at least one record.&quot;)\r\n} else {\r\n\r\n    var opt = confirm(&quot;Are you sure you want to delete selected records ?&quot;);\r\n    if (opt == true) {\r\n        var errors = &#x5B;];\r\n        var result = sforce.connection.deleteIds(records);\r\n        if (result &amp;&amp; result.length) {\r\n            var numFailed = 0;\r\n            var numSucceeded = 0;\r\n            for (var i = 0; i &lt; result.length; i++) {                 var res = result&#x5B;i];                 if (res &amp;&amp; res.success == 'true') {                     numSucceeded++;                 } else {                     var es = res.getArray(&quot;errors&quot;);                     if (es.length &gt; 0) {\r\n                        errors.push(es&#x5B;0].message);\r\n                    }\r\n                    numFailed++;\r\n                }\r\n            }\r\n            if (numFailed &gt; 0) {\r\n                alert(&quot;Failed: &quot; + numFailed + &quot;nSucceeded: &quot; + numSucceeded + &quot; n Due to: &quot; + errors.join(&quot;n&quot;));\r\n            } else {\r\n                alert(&quot;Number of records deleted: &quot; + numSucceeded);\r\n            }\r\n        }\r\n        window.location.reload();\r\n    }\r\n}\r\n<\/pre>\n<p>In above code, we only need to change line number 4 for Object Type.<br \/>\nOnce you are done with above button, add button in Search Layout&#8217;s List View as shown in below Image.<\/p>\n<figure id=\"attachment_3300\" aria-describedby=\"caption-attachment-3300\" style=\"width: 529px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Salesforce-Search-Layout.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" wp-image-3300 \" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/05\/Salesforce-Search-Layout.png?resize=529%2C193&#038;ssl=1\" alt=\"Salesforce Search Layout\" width=\"529\" height=\"193\" \/><\/a><figcaption id=\"caption-attachment-3300\" class=\"wp-caption-text\">Salesforce Search Layout<\/figcaption><\/figure>\n<p><a title=\"Salesforce Cookbook\" href=\"https:\/\/ap1.salesforce.com\/help\/doc\/en\/links_useful_custom_buttons_mass_delete.htm\" rel=\"nofollow\">Code taken from Salesforce Cookbook<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click &#8220;Delete&#8221; button. In this example, we will create a simple List View button and add on &#8220;Search Layout&#8221; of that object. So, create a new Custom Button with following property: Display Type\u00a0: \u00a0List Button [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[9],"tags":[270,126,140,331,269],"class_list":["post-3299","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-ajax-toolkit","tag-javascript","tag-listview","tag-salesforce","tag-salesforce-ajax-toolkit"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4394,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit\/","url_meta":{"origin":3299,"position":0},"title":"Create and update records using Javascript button in Salesforce- Ajax Toolkit","author":"Jitendra","date":"April 21, 2015","format":false,"excerpt":"On this blog we have already seen \"how to use Ajax Toolkit to mass update records\" without writing any Apex code. In this article as well, we will use Ajax Toolkit to add custom button in Account page layout and update record. There are endless possibilities and use-cases where this\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Update Record using Javascript","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3112,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-13\/","url_meta":{"origin":3299,"position":1},"title":"Salesforce Interview Question \u2013 Part 13","author":"Jitendra","date":"September 25, 2012","format":false,"excerpt":"121 : Consider we have overall 90% code coverage however there is one class which have 0% code coverage. Can we still able to deploy that class on production? Ans : Yes. Minimum 1% required for every trigger and there is no such restriction for Apex class. 122 : How\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2470,"url":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/salesforce-tutorial-create-simple-ajax-based-visualforce-page\/","url_meta":{"origin":3299,"position":2},"title":"Salesforce Tutorial &#8211; Create Simple Ajax based Visualforce page","author":"Jitendra","date":"October 17, 2011","format":false,"excerpt":"Salesforce Tutorial - Step by step tutorial to create AJAX based application in visualforce page with Apex class","rel":"","context":"In &quot;Web Technology&quot;","block_context":{"text":"Web Technology","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/"},"img":{"alt_text":"Simple AJAX demo in salesforce using visualforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Simple-AJAX-demo-in-salesforce-using-visualforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3185,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-14\/","url_meta":{"origin":3299,"position":3},"title":"Salesforce Interview Question \u2013 Part 14","author":"Jitendra","date":"February 28, 2013","format":false,"excerpt":"131. What will happen if you try to update record in After Trigger Context? Ans : You will get an error saying \"record is Read only\". 132. Let's say we have to update the same record in After Trigger context. Is there any way or workaround? Ans : If we\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3411,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex-interview-question-salesforce-part-16\/","url_meta":{"origin":3299,"position":4},"title":"Apex Interview Question \u2013 Salesforce &#8211; Part 16","author":"Jitendra","date":"July 28, 2013","format":false,"excerpt":"151. Give Sample Code Snippet of Apex that that will show that how Parent and Child record can be inserted in Single Statement ? Ans : It can be done with help of External Id. [java] Date dt = Date.today().addDays(7); Opportunity newOpportunity = new Opportunity(Name = 'shivasoft', StageName = 'Prospecting',\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5595,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/dynamically-remove-xml-content-from-metadata-before-salesforce-deployment-using-xmltask-video\/","url_meta":{"origin":3299,"position":5},"title":"Dynamically remove XML content from metadata before Salesforce deployment using xmlTask &#8211; Video","author":"Jitendra","date":"August 18, 2016","format":false,"excerpt":"Example - automatically remove listview before deployment","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Using XMLTask in ANT for Salesforce Deployment","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/08\/2016-07-15.png?fit=922%2C519&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/08\/2016-07-15.png?fit=922%2C519&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/08\/2016-07-15.png?fit=922%2C519&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/08\/2016-07-15.png?fit=922%2C519&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=3299"}],"version-history":[{"count":1,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3299\/revisions"}],"predecessor-version":[{"id":3970,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/3299\/revisions\/3970"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=3299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=3299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=3299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}