function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
------BatchUpdateAccountCountField.apxc global class BatchUpdateAccountCountField implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext bc) { String query = 'SELECT Id,Count__c,(SELECT Id FROM Contacts) FROM Account'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext bc, List<Account> accountList){ if(accountList.size()>0){ for(Account accObj : accountList){ if(accObj.contacts != Null) accObj.Count__c = accObj.contacts.size(); } update accountList; } } global void finish(Database.BatchableContext bc){ System.debug('Successfully Updated'); } } ------BatchUpdateAccountScheduler.apxc //To schedule above apex class global class BatchUpdateAccountScheduler implements Schedulable { global void execute(SchedulableContext sc){ BatchUpdateAccountCountField Obj = New BatchUpdateAccountCountField(); Database.executeBatch(Obj); } public static void scheduleBatchUpdateAccountScheduler(){ String cronExp1 = '0 5 * * * ? *'; String cronExp2 = '0 10 * * * ? *'; String cronExp3 = '0 15 * * * ? *'; String cronExp4 = '0 20 * * * ? *'; String cronExp5 = '0 25 * * * ? *'; String cronExp6 = '0 30 * * * ? *'; String cronExp7 = '0 35 * * * ? *'; String cronExp8 = '0 40 * * * ? *'; String cronExp9 = '0 45 * * * ? *'; String cronExp10 = '0 50 * * * ? *'; String cronExp11 = '0 55 * * * ? *'; String cronExp12 = '0 0 * * * ? *'; BatchUpdateAccountScheduler schedulerObj = New BatchUpdateAccountScheduler(); System.schedule('Update account count Field1', cronExp1, schedulerObj); System.schedule('Update account count Field2', cronExp2, schedulerObj); System.schedule('Update account count Field3', cronExp3, schedulerObj); System.schedule('Update account count Field4', cronExp4, schedulerObj); System.schedule('Update account count Field5', cronExp5, schedulerObj); System.schedule('Update account count Field6', cronExp6, schedulerObj); System.schedule('Update account count Field7', cronExp7, schedulerObj); System.schedule('Update account count Field8', cronExp8, schedulerObj); System.schedule('Update account count Field9', cronExp9, schedulerObj); System.schedule('Update account count Field10', cronExp10, schedulerObj); System.schedule('Update account count Field11', cronExp11, schedulerObj); System.schedule('Update account count Field12', cronExp12, schedulerObj); } }
Greetings to you
I have solved your question the BatchUpdateAccountCountField.apxc class is a batch class and BatchUpdateAccountScheduler.apxc class
is scheduler class to schedule BatchUpdateAccountCountField.apxc class in evety 5 minutes.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha