Activity Forums Salesforce® Discussions How can we Delete mass Accounts from org using Dml operation in salesforce?

  • Kumar

    Member
    January 6, 2017 at 1:34 pm

    Hi vikas,

    There is no soql command to delete rows directly. What you can do instead is to create a list with all the accounts in your org and then delete that list.

    For example:

    list<Account> acc = [SELECT id FROM Account];                                                                                                 delete acc;

    Hope this helps.

  • shariq

    Member
    August 4, 2017 at 10:16 am

    Hi Vikas,

    You may use Batch Class to delete all records of Account sobject.

    For Example :-

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

    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos