You need to sign in to do that
Don't have an account?
Jon Gradman
batch apex test class help
Hi all,
I've been a Salesforce admin for 2 years and have experience with point and click development like Visual Workflow and Visualforce controllers but I don't have a lot of experience writing test classes. This test class is coming up short with 43% coverage:
Here is the class code. The reason I am updating the code is to avoid being timed out by a trigger, which is part of the Lookup Helper managed package. Our batchable APEX code below runs every night to update all of our customer Accounts in SFDC so that various workflows and alerts fire when they are relevant. Since installing this package, however, we are having timeout errors. As a second question, will this code help increase the CPU time to avoid an error?
Any suggestions? All help appreciated thank you.
- Jon
I've been a Salesforce admin for 2 years and have experience with point and click development like Visual Workflow and Visualforce controllers but I don't have a lot of experience writing test classes. This test class is coming up short with 43% coverage:
@isTest private class AcctUpdateTest { public static testMethod void testschedule() { Test.StartTest(); AccountsUpdate sh1 = new AccountsUpdate(); String sch = '0 0 23 * * ?'; system.schedule('Test check', sch, sh1); Test.stopTest(); } }
Here is the class code. The reason I am updating the code is to avoid being timed out by a trigger, which is part of the Lookup Helper managed package. Our batchable APEX code below runs every night to update all of our customer Accounts in SFDC so that various workflows and alerts fire when they are relevant. Since installing this package, however, we are having timeout errors. As a second question, will this code help increase the CPU time to avoid an error?
global class AccountsUpdate implements Database.Batchable<sObject>,Schedulable { global Database.QueryLocator start(Database.BatchableContext bc) { String query = 'SELECT Id, Type FROM Account'; // create the query to run return Database.getQueryLocator(query); //get all of the data in the start } global void execute(Database.BatchableContext bc,List<sObject> objects){ //because a generic list is passed in, you have to 'box' it (type set) it to the Right Object. List<Account> acctList = [Select Id, Type From Account Where Type = 'Customer - Current' OR Type = 'Customer - Current - Overdue' ]; List<Account> updAccounts = new List<Account>(); integer counter = 0; for(Account thisAcct : acctList) { updAccounts.add(thisAcct); counter++; if (counter == 20) { update(updAccounts); } } if (counter > 0) { update(updAccounts); } } global void finish(Database.BatchableContext BC) { AsyncApexJob aaj = [Select Id, Status, NumberOfErrors, JobItemsProcessed, MethodName, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()]; } global void execute(SchedulableContext sc){ Database.executeBatch(new AccountsUpdate()); } }The old code just selected all customers and attempted an update, but doing 200 records at a time was making the triggers associated with Lookup Helper to fail / timeout - since they are written for every update on Accounts and not for specific fields.
Any suggestions? All help appreciated thank you.
- Jon
All Answers