function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sanjana BillaSanjana Billa 

Hello..!! My requirement is to select multiple records from case object and delete at once. Please provide me the solution how can this be solved.

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sanjana,

Greetings to you!

One way to delete using Developer Console is to first execute your query
SELECT Id, Subject, Status from Case
Then highlight all the result rows and click on the Delete Row button at the bottom.

Another way to delete multiple cases is through Mass Delete Records.
Go to Setup -> Quick Find -> Mass Delete Records -> Mass Delete Cases -> Search

You can also create a Visualforce page. Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="DeleteSelectedCasesC">
    <apex:form >
        <apex:pageblock title="Cases">
            <apex:pageBlockTable value="{!wrp}" var="c">
                <apex:column >
                    <apex:inputCheckbox value="{!c.check_box}" />
                </apex:column>
                <apex:column value="{!c.cs.CaseNumber}"/>
                <apex:column value="{!c.cs.Subject}"/> 
                <apex:column value="{!c.cs.Status}"/> 
            </apex:pageBlockTable>
            <apex:pageBlockButtons location="Bottom">
                <apex:commandButton id="deleteit" value="Delete Selected" action="{!delete_now}"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>

Controller:
public class DeleteSelectedCasesC {
    
    public List<WrapperClass> wrp {get;set;}
    public Boolean check_box {get;set;}
    public List<Case> del {get;set;}
    
    public DeleteSelectedCasesC(){
        wrp = new List<WrapperClass>(); 
        for(Case c : [SELECT Id, CaseNumber, Subject, Status FROM Case LIMIT 10]){
            wrp.add(new WrapperClass (c, false));
        }
    }
    
    public PageReference delete_now(){
        del=new list<Case>();
        for(WrapperClass wc: wrp){
            if(wc.check_box){
                del.add(wc.cs);
            }
        }
        delete del;   
        PageReference pr = new PageReference(System.currentPageReference().getURL());
        pr.setRedirect(true);
        return pr;
    }
    
    public class WrapperClass {
        public Case cs {get; set;}
        public Boolean check_box {get; set;}
        
        public WrapperClass(Case cs, Boolean check_box){
            this.cs = cs;
            this.check_box = check_box;
        }
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Sanjana BillaSanjana Billa
Hello Khan,
Thank you for your quick response. Can we achieve this using triggers?