Skip to main content
kishore koni ha fatto una domanda in #Apex
Hi all,

Delete records batch apex account ,contacts ,opportunity and cases in single batchclass
5 risposte
  1. 10 mag 2016, 12:20
    Hi ,

    Please check the below code for delete Accounts, Contacts and Opportunities records using single batch class.

     

    Global 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){

    }

    }

    Execute the below code in anonymous block

     

    string 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);

    Please check the below links for learning Batch Apex.

    https://developer.salesforce.com/trailhead/module/asynchronous_apex

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

    Hope this helps you!

    Best Regards,

    Jyothsna

     
0/9000