You need to sign in to do that
Don't have an account?

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