+ Start a Discussion
ForceLoverForceLover 

Rollup summary filtration based on current month

 

Hi Everyone

 

I have two custom objects Employee (Master) , submission (Detail).My rollup in Employee gives no of submissions made by each .I need to filter these submissions based on current month and for each employee... for this  i'm planning to write a trigger . here i created a count field on employee everytime if a record enter into submission object the count should be incremented.but i need employee wise submissions count on monthly basis could you please help me out.Every time the count should be reset to zero on next month. is it better to write a trigger or a class.

 

Thanks in advance

Ritesh AswaneyRitesh Aswaney

A trigger will cut it if you can deal with the Submission Count being out of Sync until the first Submission of the month is created. (You can create a DatField Submission_Last_Updated__c, which is updated by the trigger, each time is updating the count field)


So when a trigger runs, it always check if the Month of the current data is the same as the Month on the Submission_Last_Updated__c, if not it resets it to 0 and adds 1 to it, so it sets it to 1.

 

Or the more elegant solution will be scheduled (Batch) apex, which runs each night and selects all Submissions from that month and recalculates the count each night. You can of course schedule this as frequently as you'd like.

ForceLoverForceLover

Thanks for replying Ritesh,  could you please share some sample code for this actually i'm in a bad need of this.......

how to retrieve current month records in submissions ..i need to display the count of submissions in employee object

 

 

 

 

                                      

ForceLoverForceLover

Hi Ritesh upto know this was my approach here i'm missing Submission_last_modified_date__c ,could you please make changes for this 

 

 

global class Submissioncount implements Database.Batchable<sobject>,Schedulable {

global final string query= 'select Name,Current_Month__c,Date_of_Submission__c from Submission__c';
global String St;
global Submissioncount(){

Datetime dt=Datetime.now();
St=dt.format('MMMM');
}
global void execute(SchedulableContext SC) {

Submissioncount MR2 = new Submissioncount();
ID batchprocessid = Database.executeBatch(MR2,50);

}
global Database.QueryLocator start(Database.BatchableContext BC)
{

return Database.getQueryLocator(this.query);
}

global void execute(Database.BatchableContext BC, List<Submission__c> scope)
{
List<Submission__c> S1=new List<Submission__c>();

for(Submission__c S2:Scope)
{
for(Employee__c E:[select id,count__c from Employee__c]){
if(St==S2.Current_Month__c){

}
}
}
}
global void finish(Database.BatchableContext BC){

}
}