[SalesForce] Custom Report Generation -VF Salesforce

I have a requirement where I need to create a custom VF report which will be created automatically every month and will be sent to the respective client along with email template.

Though I have not started working on this but I am clear with how to create my report.

I have doubt regarding automatic report generation every month?
How can I automatically generate the reports every month?
How can I keep track of all the reports generated every month?

I do need to send those reports to the client along with email template.

Best Answer

you can use apex scheduler where you can specify date and time to execute code. Please follow below link. I used the same for sending reports via mail on dialy basis.

Apex Scheduler

global class TestScheduledApexFromTestMethod implements Schedulable {
// This test runs a scheduled job at midnight Sept. 3rd. 2022

public static String CRON_EXP = '0 0 0 3 9 ? 2022';

global void execute(SchedulableContext ctx) {
  CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime
            FROM CronTrigger WHERE Id = :ctx.getTriggerId()];

  System.assertEquals(CRON_EXP, ct.CronExpression);
  System.assertEquals(0, ct.TimesTriggered);
  System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));

  Account a = [SELECT Id, Name FROM Account WHERE Name = 
              'testScheduledApexFromTestMethod'];
  a.name = 'testScheduledApexFromTestMethodUpdated';
  update a;
  }   
}
Related Topic