Hi Guys,
I had a scenario where i need to delete the records of a object and send those records to a particular Email Id as CSV File. This can be done with DATA EXPORT option in salesforce,But if you wont check the link of Data Export then the data will be lost after 2 days i.e the reason we have written a batch apex and a schedule class to delete the records and send those deleted records to a mail id as csv file.Here every thing is automated and taken care by the code.
Batch Class:-
Schedule Class:-
NOTE:ld.query should be in a single line because its a dynamic query.
Now you can schedule your schedule class with UI or by a piece of code.
When you want the schedular to call your batch class to delete the records.
Schedule to run my Schedule class at every day at 11 pm using system log:-
Now you can see at 11 pm every day you batch class will delete all the lead records and send them to the given mail id as CSV file.
I had a scenario where i need to delete the records of a object and send those records to a particular Email Id as CSV File. This can be done with DATA EXPORT option in salesforce,But if you wont check the link of Data Export then the data will be lost after 2 days i.e the reason we have written a batch apex and a schedule class to delete the records and send those deleted records to a mail id as csv file.Here every thing is automated and taken care by the code.
Batch Class:-
Schedule Class:-
NOTE:ld.query should be in a single line because its a dynamic query.
Now you can schedule your schedule class with UI or by a piece of code.
When you want the schedular to call your batch class to delete the records.
Schedule to run my Schedule class at every day at 11 pm using system log:-
Now you can see at 11 pm every day you batch class will delete all the lead records and send them to the given mail id as CSV file.
Hi is there a way to do this for new leads? I do not need to delete the leads, just need to have Salesforce email out a CSV file the new leads that comes in to our SF Instance daily.
ReplyDeleteNice post. For more real time scenarios watch on --SFDC GURUKUL
ReplyDeleteCode is good but are you aware of Email invocation Limits in salesforce.
ReplyDeleteIf i have 50000 records to delete and send email.In these case Email invocation Limit Exceeds.
So,try to use it in Finish Method by Implementing Database.stateful interface.Please correct me if im wrong..Thank you