You need to sign in to do that
Don't have an account?
buggs sfdc
BATCH APEX TO COUNT THE LEADHISTORY YEARLY WISE
HI
can anyone help me out in writing me a bacth apex to count the LeadHistory data on yearly basis,i have a requirment to count the total number of (Createddate Column )LeadHistory data yearly wise, through developer console i can able to count the total number of LeadHistory,but when am trying to count it on yearly basis,the server is timing out,so i hope for the yearly count we have to write a batch apex ..suppose i want last 5 years data so here we have to create a table with 5 coloumns and we can update that count in that particular table,please advise me wheather am on right track?? thanks in advances..really apprecaite quick responses.
can anyone help me out in writing me a bacth apex to count the LeadHistory data on yearly basis,i have a requirment to count the total number of (Createddate Column )LeadHistory data yearly wise, through developer console i can able to count the total number of LeadHistory,but when am trying to count it on yearly basis,the server is timing out,so i hope for the yearly count we have to write a batch apex ..suppose i want last 5 years data so here we have to create a table with 5 coloumns and we can update that count in that particular table,please advise me wheather am on right track?? thanks in advances..really apprecaite quick responses.
(It might be easier to use [select count() from Lead where ...] and set the where condition between the desired dates, but this will be a slow process (so batch run in the evening and store the result somewhere). Otherwise use a report?
HI Tameer
Thanks for the reply,can you help me out with the following code to solve with batch apex.here am trying to query from LeadHistory Table and want to show that count on another table(Project__c),so here am created 2 columns like X2011__c,X2012_c, and need to show that count in this particular columns,please help me out in resolving this issue.
global class LeadHisCount implements Database.Batchable <sobject> {
global Database.queryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('select calendar_year(createddate), calendar_month(createddate) from LeadHistory group by calendar_year(createddate), calendar_month(createddate) order by calendar_year(createddate),calendar_month(createddate)');
}
global void execute(Database.BatchableContext bc, LIST< Project__c > LHis) {
List< Project__c > depUPdLst = new List< Project__c >();
for(Project__c LH: LHis) {
Project__c LHT = (Project__c) LH;//Type Casting.
//LHT.X2011__c = 'Count1';
//LHT.X2012__c = 'Count';
depUPdLst.add(LHT);
}
if(depUPdLst.size() > 0)
update depUPdLst;
}
global void finish(Database.BatchableContext bc) {
//Post Commit logic like sending emails for the success or failures of the batches.
AsyncApexJob a = [select id, Status, NumberOfErrors,JobItemsProcessed,TotalJobItems, CreatedBy.Email from AsyncApexJob where id =: bc.getJobId()];
Messaging.singleEmailMessage mail = new Messaging.singleEmailMessage();
mail.setToAddresses(new String[]{a.CreatedBy.Email});
mail.setSubject('Batch Class Result');
mail.setHtmlBody('The batch Apex job processed ' + '<b>' + a.TotalJobItems + '</b>' +
' batches with '+ '<b>' + a.NumberOfErrors + '</b>' + ' failures.');
//sendEmail methods
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail});
/*** Scheduling in minutes or hours ***/
/*//Create object for schedulable class
SchedulableUsage su = new SchedulableUsage();
//Preparing chron_exp
Datetime sysTime = System.now();
sysTime = sysTime.addminutes(6);
String chron_exp = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' +
sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
System.schedule('Dep Update'+sysTime.getTime(),chron_exp, su);*/
}
}
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm