
답변 5개

Hi ,Please check the below code for delete Accounts, Contacts and Opportunities records using single batch class.
Execute the below code in anonymous blockGlobal class BatchMassDeleteRecs Implements Database.batchable<sobject>{
global final string query;
global BatchMassDeleteRecs(string q){
query=q;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<SObject> scope){
delete scope;
}
global void finish(Database.BatchableContext BC){
}
}
Please check the below links for learning Batch Apex.https://developer.salesforce.com/trailhead/module/asynchronous_apexhttps://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htmHope this helps you!Best Regards,Jyothsnastring str='select id,name,(select id,name from contacts), (select id, name from opportunities) from Account limit 1';
BatchMassDeleteRecs bdt=new BatchMassDeleteRecs(str);
Database.executeBatch(bdt);
system.debug(bdt);