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
Sushmitha AnabthulaSushmitha Anabthula 

i'm trying to delete candidates using batch apex but couldn't perform

public class BatchApex implements database.Batchable<sobject>
{
    public database.QueryLocator start(database.BatchableContext bc)
    {
        String q ='select id from Candidate__c';
        Return database.getQueryLocator(q);      
        
    }
    public void execute(database.BatchableContext bc, list<Candidate__c> can)
    {
        delete can;
          
        
    }
    public void finish(database.BatchableContext bc)
    { 
        
    }

}
Isha BansalIsha Bansal
Please paste the issues/error while trying to do it
SwethaSwetha (Salesforce Developers) 
HI Sushmitha ,
Please include the error message that you are seeing.

Sharing this sample code that deletes account records.
public class DeleteAccountsBatch implements Database.Batchable<sObject> {
    
    public Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id FROM Account limit 2';
        return Database.getQueryLocator(query);
    }
    
    public void execute(Database.BatchableContext bc, List<sObject> scope) {
        // Convert sObjects to Accounts
        List<Account> accounts = (List<Account>) scope;
        // Delete the accounts
        system.debug(accounts);
        delete accounts;
    }
    
    public void finish(Database.BatchableContext bc) {
        // Handle any post-processing tasks
    }
    
}

Run the below in the anonymous block
DeleteAccountsBatch batch = new DeleteAccountsBatch();
Database.executeBatch(batch);

This code will delete the account records provided there are no dependencies(associated  cases with the account)

If this information helps, please mark the answer as best. Thank you