How to work with Button to Delete records from List view Page of Subject

| By Webner

The below Screenshot is showing delete button on the list view page of the object.
Following is the code for the same (clicking the Delete button on the list view page which will get a list of Ids of select records)

Login to salesforce where you have to perform Delete records from List view Page of Subject(particular object)

First of all, we need to create a VF page and Apex Class.

  • We will select the VF page when we will create a button to object for sending success messages and error messages after a successful operation.
  • Apex Class to get selected records to act on them.
  1. VF PAGE
    <apex:page standardController="AcctSeed__Cash_Disbursement__c" title="Batch Delete "
    extensions="DeleteCashDisbursement" recordSetVar="accs" action="{!redirectToLC}" sideBar="false" lightningStylesheets="redirectToLC">
    <apex:pageMessages escape="false"/>
    <apex:pageBlockButtons >
    <apex:commandButton action="{!DeleteCashDisbursements}" value="Delete" immediate="true" rendered="{!ishide}" status="spinner"/>

    The output of the VF page
  2. Apex Class
    public with sharing class DeleteCashDisbursement {
    public List<objectAPIname> selAccLst;
    public String accIds;
    // Constructor
    public DeleteCashDisbursement(ApexPages.StandardSetController cntlr){
    selAccLst = cntlr.getSelected();
    selectedCDList = [SELECT Id, AcctSeed__Status__c,AcctSeed__AP_Voucher_Count__c,Name FROM AcctSeed__Cash_Disbursement__c where Id IN :selAccLst];
    if(selAccLst.size() > 0){
    delete selAccLst;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,
    'Number of records processed for deleting '+'('+selAccLst.size() + ')'));
  3. Go to Setup=>ObjectManger
    Search for the object from Object Manager
    Open the object and go to Buttons, Links, and Actions Create a button on the same object and click. New Button or Link option like in the following screenshot.
  4. Click on the NewButton or Link and fill the information in the following screen and then save
  5. Click on List View Button Layout and the right side icon
  6. After clicking the icon the following window will appear, drag the button from available buttons to selected buttons and then save.


Leave a Reply

Your email address will not be published. Required fields are marked *