You need to sign in to do that
Don't have an account?
siree ganti
Batch Apex Class to calculate average year-to-date, average month-to-date, and daily total
Hi All,
The following code doesn't seem to work. Trying to calculate daily total for support cases closed, average month-to-date (mtd), average year-to-date ytd for reporting purposes. Please help!!
here's the code:
global class batchA0806 implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
Integer DailyTotal = SELECT COUNT() FROM Cases where ClosedDate=TODAY ;
Integer a = SELECT COUNT() FROM Cases where ClosedDate=THIS_MONTH;
Integer b = SELECT COUNT() FROM Cases where ClosedDate=THIS_YEAR;
return Database.getQueryLocator(query1);
return Database.getQueryLocator(a);
return Database.getQueryLocator(b);
}
global void execute(Database.BatchableContext BC)
{
mtd = a/THIS_MONT;
ytd = b/THIS_YEAR;
update mtd;
update ytd;
update DailyTotal;
}
global void finish(Database.BatchableContext BC)
{
}
}
The following code doesn't seem to work. Trying to calculate daily total for support cases closed, average month-to-date (mtd), average year-to-date ytd for reporting purposes. Please help!!
here's the code:
global class batchA0806 implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
Integer DailyTotal = SELECT COUNT() FROM Cases where ClosedDate=TODAY ;
Integer a = SELECT COUNT() FROM Cases where ClosedDate=THIS_MONTH;
Integer b = SELECT COUNT() FROM Cases where ClosedDate=THIS_YEAR;
return Database.getQueryLocator(query1);
return Database.getQueryLocator(a);
return Database.getQueryLocator(b);
}
global void execute(Database.BatchableContext BC)
{
mtd = a/THIS_MONT;
ytd = b/THIS_YEAR;
update mtd;
update ytd;
update DailyTotal;
}
global void finish(Database.BatchableContext BC)
{
}
}
Can you please expalin your requirment bit detail like what exactly you want .I don't think you need batch apex for this .
1.Like in which object you need to update the case details .
2.When you want to execute this class .As you are going to calculate closed cases or cases this Year THis Month and Today. So where you need to update the count .
Don't you need the previuos month and yesterday count as well .
Thanks
Manoj
The requirement is to show a dashboard component with Daily Total for # of closed cases, Average month to date, and Average year to date for # of closed cases. This component must be refreshed daily. In order to do a dashboard component, I need a report. But I cannot do the above calculations within the report formula fields. Therefore, I'm doing a batch class on a custom object with three custom fields i.e., DailyTotal, AvgMtd, AvgYtd. Makes sense?
Siree
Hi siree ganti,
It's ok ,correct me if I am wrong. You need to create one record in your custom object with three values .So instead of batch apex you can do one thing just create a schedule apex class .
In execute method you can do all three query to get the value and create one record of your custom object .and schedule that class as per your need .
Any calculation you need you can do inside excute method .Let m eknow if it helps .
Siree