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
B NagarjunaB Nagarjuna 

how to run the batch program in my developer instance

 

 

global class deleteAccounts implements Database.Batchable<Sobject>
{
global final String Query;
global deleteAccounts(String q)
{
Query=q;

 

}

global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<SObject> scope)
{
List<Account> lstAccount = new list<Account>();
for (SObject s : scope) //for all objects from our query

{
Account a = (Account)s;
lstAccount.add(a);

}
Delete lstAccount;
}

global void finish(Database.BatchableContext BC)
{
//Send an email to the User after your batch completes
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'na@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

 

 

now iam learning stage in batch apex............so how to run the above batch program,i save this apex program in my developer instance with out errors but i dnt knw how to run and how to get output

RockDeveloperRockDeveloper

Create New Schedular Class to call your batch.

But simplaest way is Go to Apex Classes ---> Scheduled Apex button

Click on it and Select your Batch class and Time when to execute your batch.

If you want to check your batch run or not  then go  to  Monitoring Section and in that go to Scheduled job...you get information from there whether your batch class run or not?

 

@anilbathula@@anilbathula@
HI arjunsf

just try this with snippet in debuglog:-

id usrid='00590000000iedd';
String query='SELECT Id, Name, Ownerid FROM Account WHERE ownerid=\'' +usrid+ '\'';
deleteAccounts reassign = new deleteAccounts(query);
database.executebatch(reassign);

if you want to schedule the batch class then use system.schedule

String sch = '0 0 * * * ?';
system.schedule('SCheduled Job',sch,reassign);