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.
record-1
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)

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

Step.2
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:pageBlock>
    <apex:pageMessages escape="false"/>
    <apex:pageBlockButtons >
    <apex:commandButton action="{!DeleteCashDisbursements}" value="Delete" immediate="true" rendered="{!ishide}" status="spinner"/>
    </apex:pageBlock>
    </apex:page>

    The output of the VF page
    record-2
  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,
    'Success:'));
    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
    record-3
    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.
    record-4
  4. Click on the NewButton or Link and fill the information in the following screen and then save
    record-5
  5. Click on List View Button Layout and the right side icon
    record-6
  6. After clicking the icon the following window will appear, drag the button from available buttons to selected buttons and then save.
    record-7

    record-8

Leave a Reply

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