You need to sign in to do that
Don't have an account?
Hari N 20
Generate records from one object to another using batch apex
Hi All,
I want to generate records from one object into another object. I have written a trigger for this and working fine.
I want this output in batch apex form
What ever I get the records in object1 today, I want a schedule batch apex that all records should get create in object2 at Midnight only.
How can I do this?
Please provide me syntax
Thanks in Advance
Regards,
Hari
I want to generate records from one object into another object. I have written a trigger for this and working fine.
I want this output in batch apex form
What ever I get the records in object1 today, I want a schedule batch apex that all records should get create in object2 at Midnight only.
How can I do this?
Please provide me syntax
Thanks in Advance
Regards,
Hari
Please check with below links from community boards which might help you to accelerate with the above requirement.
- https://developer.salesforce.com/forums/?id=906F0000000Ac5sIAC
- https://developer.salesforce.com/forums/?id=906F0000000kG4LIAU
- http://salesforce.stackexchange.com/questions/32261/how-to-create-schedule-batch-apex-which-returns-list-of-object-records
- http://stackoverflow.com/questions/21859244/need-help-in-writting-schedulebatch-apex-class
Good Luck.Best Regards,
Nagendra.P
Batch Class:
Shedulable class:
Cron expression;
Let me know if you have any issue.
Mark it as best answer if it works.
THanks.
I have implemeted the same.
But, I am not able to see in apex jobs. Even record also not created
Have you executed cron expression in execute anonymous?If don't plese do that.
The code will run everyday at 11:00 PM.So you won't see results right away
Thanks.
Thank you
It is not working. I have changed scheduling time to 6 PM.
I checked after 6 PM. No record is created in Object2.
Please help me.
Batch Apex Class:
---------------------------------------------------------------
global class BatchapexExmple implements database.Batchable<Sobject> {
global database.QueryLocator start(database.BatchableContext bc){
string query = 'select id,name,phone,CreatedDate from account where CreatedDate =Today';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc , list<account> acc ){
list<contact> con = new list<contact>();
for(account a : acc){
contact c = new contact();
c.LastName = a.name;
c.Phone = a.phone;
con.add(c);
}
insert con;
}
global void finish(database.BatchableContext bc){
}
}
Schedulable apex Class:
-------------------------------------------------------------------------
global class ScheduableApex implements Schedulable{
global void execute(schedulableContext sc){
BatchapexExmple ba = new BatchapexExmple();
database.executeBatch(ba);
}
}
Execution:
---------------------------------------------------
ScheduableApex sc2 = new ScheduableApex();
string str = '59 59 23 * * ?';
system.schedule('job2', str, sc2);