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)
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.
- 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
- 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() + ')')); - 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.
- Click on the NewButton or Link and fill the information in the following screen and then save
- Click on List View Button Layout and the right side icon
- After clicking the icon the following window will appear, drag the button from available buttons to selected buttons and then save.