You need to sign in to do that
Don't have an account?
TiborM
How to resolve limit 100 records in bulk operation?
Hi all,
i need somehow make bulk operation in apec class for more than 100 records. To make easier to understand i write little example what I need to do. Please don't aske me why I need it - because.
global class AccountsOpenCases implements Schedulable { public static String CRON_EXP = '0 0 8 * * ?'; global void execute(SchedulableContext SC) { Account[] accs = [SELECT id, name, NO_OF_OPEN_CASES__c from Account]; for (Account item : accs) { int i = [SELECT count() from Case where STATUS != 'CLOSE' and status != 'PENDING CLOSE' and status != 'SERVICE REQUEST' and account = :item.id]; item.NO_OF_OPEN_CASES__c = i; update item; } } }
First of all, why are using "Schedulable" interface if all you want to do is update records. Schedulable interface is when you want to schedule another Apex class to run. It is not a best practice to put your logic in this class. I'd write a class that implements the Batchable interface and call that from your schedulable class below. Batchable interfaces can process a very large number of records.
this is something which I don't know..
We need schedulable to run this class every day. I didn't know that something like Batchable interface exists...
thank you, i'll try it.
hi,
i wrote Batchable class, but now i have problem with scheduling
class code:
Test method:
GetCases.query =
'SELECT Id, Name FROM Account LIMIT 200'; ID batchprocessid = Database.executeBatch(GetCases, 200); test.stoptest(); } }Schedule Class:
When I shcedule it and look into SETUP -> MONITORING -> APEX JOBS i saw than it have 15 FAILURES.
Why it fail? How can I debug it?
How can I run this batch in some debug mode or how is possible to run classes by press some button or wahtever and see results??
My guess for why it failed is because you have a SOQL and an update inside a for loop and you will hit governor limits in doing so. Here's a rough idea of how you would go about changing the execute method.
Please refer to the following link on "bulkifying" your trigger/apex code:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_patterns_bulk.htm
Apex now allows you to do "Select ...group by". for more information on that please refer to:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select.htm