You need to sign in to do that
Don't have an account?
Venkata Sumedha singanamala
how to update the status column using schedule apex
Hi All,
I have a small requirment I want to update the status column in the EMP custom tab with "Batched" and "Not Batched" I mean some column should have as "Batched" and some as"Not Batched" and this should be done at a specifed time
Please help on this. For your reference Please find the screen shot attached.
Regards,
Seshagiri
I have a small requirment I want to update the status column in the EMP custom tab with "Batched" and "Not Batched" I mean some column should have as "Batched" and some as"Not Batched" and this should be done at a specifed time
Please help on this. For your reference Please find the screen shot attached.
Regards,
Seshagiri
If you want to wirte a batch and want to schedule a apex class then below code heps you.
Just customize query and field and object api names
Now here is schedule class which will run batch when schedule class execte
Here is code to schedule scheduleMerge class, You need to tell when it should be run by cron exp.
For corn expression : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
If you want run batch directly without scheduling
You can do this with schedule Apex. Create a class which implements Schedulable interface.(Setup --> customize --> Apex Classes --> New)
Refer Below code:
after saving the above class goto Schedule Apex (Setup --> customize --> Apex Classes --> Schedule Apex ).
Select the schedule when you want to run above task.
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
global class EMPbat implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext ct){
String query='select id,status from Emp__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext ct, LIST<Emp__c> la){
for(Emp__c e:la){
e.Status__c='Batched';
}
update la;
}
global void finish(Database.BatchableContext ct){
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'seshagiri.esp@gmail.com'};
mail.settoAddresses(toAddresses);
mail.setSubject('batching Completed');
mail.setPlainTextBody('The Batch apex job has been processed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
}
}
and to execute the above code I have created the object of the above class implementing the schedulable interface
global class Empbatsch implements schedulable{
global void execute(SchedulableContext sc){
Empbat eb= new Empbat();
Database.executeBatch(eb);
}
}
please help me.. :(
Regards,
Seshagiri