You need to sign in to do that
Don't have an account?
Javagal
run time exception DML rows error
Hi I have a Web service class which is having an issue row lock contention . could you please suggest how to reduce Concurrency of these requests. Many thanks ..
error Message : Too many DML rows: 10001
Global class BulkDelayProcessUtility {
webservice static boolean BulkDelayExistingUtility(){
boolean processCompleted=true;
datetime dateNow=datetime.now();
datetime cutoff=dateNow.addMinutes(-15);
List<Id> delayReasonIds=new List<Id>();
for(Delay_Reason__c dr: [select Id from Delay_Reason__c where CreatedDate < :cutoff]){
delayReasonIds.add(dr.Id);
}
if(!delayReasonIds.isEmpty()){
try{
database.delete(delayReasonIds);
}
catch(Exception ex){
System.debug('Failed to delete existing Delay Reasons! ' +ex);
processCompleted=false;
}
}
return processCompleted;
}
}
error Message : Too many DML rows: 10001
Global class BulkDelayProcessUtility {
webservice static boolean BulkDelayExistingUtility(){
boolean processCompleted=true;
datetime dateNow=datetime.now();
datetime cutoff=dateNow.addMinutes(-15);
List<Id> delayReasonIds=new List<Id>();
for(Delay_Reason__c dr: [select Id from Delay_Reason__c where CreatedDate < :cutoff]){
delayReasonIds.add(dr.Id);
}
if(!delayReasonIds.isEmpty()){
try{
database.delete(delayReasonIds);
}
catch(Exception ex){
System.debug('Failed to delete existing Delay Reasons! ' +ex);
processCompleted=false;
}
}
return processCompleted;
}
}
Please check below link:-
https://developer.salesforce.com/blogs/engineering/2014/07/record-locking-cheat-sheet.html
https://developer.salesforce.com/blogs/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html
Thanks
Amit Chaudhary
All Answers
Hi Javagal,
You are getting "Too many DML rows: 10001" issue because your query is returining more then 10000 record. Please add Limit 10000 and try below code.
Global class BulkDelayProcessUtility
{
webservice static boolean BulkDelayExistingUtility()
{
boolean processCompleted=true;
datetime dateNow=datetime.now();
datetime cutoff=dateNow.addMinutes(-15);
List<Id> delayReasonIds=new List<Id>();
for(Delay_Reason__c dr: [select Id from Delay_Reason__c where CreatedDate < :cutoff limit 10000 ] )
{
delayReasonIds.add(dr.Id);
}
if(!delayReasonIds.isEmpty())
{
try
{
database.delete(delayReasonIds);
}
catch(Exception ex)
{
System.debug('Failed to delete existing Delay Reasons! ' +ex);
processCompleted=false;
}
}
return processCompleted;
}
}
Thanks,
Amit Chaudhary
Thank you i already done that ... but when i do that i am getting row lock contention issue. SF is suggesting us reducing the concurrency of these requests... my Question is What is the other way to optimize.
Please check below link:-
https://developer.salesforce.com/blogs/engineering/2014/07/record-locking-cheat-sheet.html
https://developer.salesforce.com/blogs/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html
Thanks
Amit Chaudhary