You need to sign in to do that
Don't have an account?
alx
DML Overflow, help!
Hey everyone,
The workhorse for my scheduled counter is giving me DML 101 issues. Anyone know how i can bulkify the following code?
global class countAgreements implements Database.Batchable<sObject>{ global final String gstrQuery = 'select ID, Number_of_Agreements__c from Opportunity'; global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(gstrQuery); } global void execute(Database.BatchableContext BC, List<sObject> scope){ List<Opportunity> listOpp = new List<Opportunity>(); for(SObject objSObject : scope){ Opportunity objOpportunity = (Opportunity)objSObject; Integer intNumberOfAgreements = [SELECT count() FROM echosign_dev1__SIGN_Agreement__c WHERE OpportunityID = :objOpportunity.ID and Is_Type_NDA__c = 1]; if (intNumberOfAgreements <> objOpportunity.Number_of_Agreements__c){ objOpportunity.Number_of_Agreements__c = intNumberOfAgreements; listOpp.add(objOpportunity); } if (listOpp.size()>0) {update listOpp;} } } global void finish(Database.BatchableContext BC){ } }
any help is greatly appreciated.
Move your update statement outside of the loop.
All Answers
Move your update statement outside of the loop.
ugh, i feel like a dumbass.
thanks tim, i'll give it a try.
Sometimes you just need a second pair of eyes. I know I do.