You need to sign in to do that
Don't have an account?
tmbarry
Too many DML rows: 10001
I know I am missing something simple here, but I getting a:
Apex script unhandled trigger exception by user/organization: 0055000000118E4/00D50000000784t
Update_NCOA_Address_v01: System.LimitException: Too many DML rows: 10001
Error Message.
1. Can someone spot my error?
2. Is there a way to put into the code or error message which record(s) triggered the error?
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c(after insert, after update) { // Update the appropriate SD_Member__c record with NCOA address from PrintSF List<SD_Member__c > recordsToUpdate = new List<SD_Member__c >(); For(printsf__Collateral_Send_History__c CSH: Trigger.new) { // Get the SD Member Id from the recipient id field //String strSDId = CSH.printsf__Recipient_ID__c; // Check to see if it is an SD Member Entry If(CSH.printsf__Recipient_ID__c!=null){ If(CSH.printsf__NCOA_Result__c == 'None') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c, NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Fowarded') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Failed') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, Address_Bad__c = True); recordsToUpdate.add(SD); } update recordsToUpdate; } }}
Thanks for the help.
Just replace
Database.SaveResult srList = Database.update(recordsToUpdate);
this one with
List<Database.SaveResult> srList = Database.update(recordsToUpdate);
All Answers
The first thing is try moving the update outside the for loop. I think that's your issue.
no exactly sure why the error, but i see 2 issues
1. update inside for loop
2. if conditions....use else if or all conditions will be checked......should'nt it be only one condition at a time ?
try if this works
One transaction can issue up to 100 SOQL queries and up to 150 DML statements.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm
Thanks,
Samba
1. Update statement inside for loop cause DML exception
2. Database methods helps us processing errors during dml operations
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c(after insert, after update) {
// Update the appropriate SD_Member__c record with NCOA address from PrintSF
List<SD_Member__c > recordsToUpdate = new List<SD_Member__c >();
For(printsf__Collateral_Send_History__c CSH: Trigger.new) {
// Get the SD Member Id from the recipient id field
//String strSDId = CSH.printsf__Recipient_ID__c;
// Check to see if it is an SD Member Entry
If(CSH.printsf__Recipient_ID__c!=null){
If(CSH.printsf__NCOA_Result__c == 'None') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c,
NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c,
NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c);
recordsToUpdate.add(SD);
}
If(CSH.printsf__NCOA_Result__c == 'Fowarded') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c);
recordsToUpdate.add(SD);
}
If(CSH.printsf__NCOA_Result__c == 'Failed') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c,
Address_Bad__c = True);
recordsToUpdate.add(SD);
}
}
}
Database.SaveResult srList = Database.update(recordsToUpdate);
for (Database.SaveResult sr : srList) {
if (sr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully inserted account. Account ID: ' + sr.getId());
}
else {
// Operation failed, so get all errors
for(Database.Error err : sr.getErrors()) {
Trigger.newMap.get(sr.getId()).addError(err.getMessage());
}
}
}
}
@tmbarry - From the error it seems that the list variable used in the DML has more than 10000 records which is causing the governor limit to be exceeded. As this is a trigger, I doubt that it will recieve more than 1000 records as a chunk even if using bulk API. Is there any other code that is being triggered? Can you add this before the update to have a check?
system.debug(recordsToUpdate.size());
In addition you can reduce the number of script statements in the if blocks by combining common assignment fields into a single block. As stated by others, the update in the for loop is another Limits exception waiting to happen so move it out of the for loop.
Venkatesh,
I received and error message with your code:
Line 44 is: Database.SaveResult srList = Database.update(recordsToUpdate);
Thoughts?
Just replace
Database.SaveResult srList = Database.update(recordsToUpdate);
this one with
List<Database.SaveResult> srList = Database.update(recordsToUpdate);
I am not sure if this solves your problem.....
Your problem is you are trying to update a list with more than 10k records.....
database.update updates only 10k records, but about the other records??...they are lost here.....database.update will work fine if you have a list with less than 10k records and have a problem with some records.....
I think you have to consider @future call to update more than 10k records
If future method is used in this scenario, how to handle error processing ?
The best way is capturing the error messages into custom object, and triggring email messages to the users.
I don't think the problem here with is handling errors, if there is bad data, may be you need to fix that first.......The issue we have here is first how to handle updating more than 10k records, I am not exactgly sure if the following code works coz I did not user future much.....But I can do it via batch apex......if you want to give a try by future try this
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c(after insert, after update) {
// Update the appropriate SD_Member__c record with NCOA address from PrintSF
List<SD_Member__c > recordsToUpdate = new List<SD_Member__c >();
For(printsf__Collateral_Send_History__c CSH: Trigger.new) {
// Get the SD Member Id from the recipient id field
//String strSDId = CSH.printsf__Recipient_ID__c;
// Check to see if it is an SD Member Entry
If(CSH.printsf__Recipient_ID__c!=null){
If(CSH.printsf__NCOA_Result__c == 'None') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c,
NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c,
NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c);
recordsToUpdate.add(SD);
}
else If(CSH.printsf__NCOA_Result__c == 'Fowarded') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c);
recordsToUpdate.add(SD);
}
else If(CSH.printsf__NCOA_Result__c == 'Failed') {
SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c,
NCOA_Address__c = CSH.printsf__Street__c,
NCOA_City__c = CSH.printsf__city__c,
NCOA_State__c = CSH.printsf__State__c,
NCOA_Zip__c = CSH.printsf__Zip_Code__c,
Address_Bad__c = True);
recordsToUpdate.add(SD);
}
}
}
asyncApex.processUpdate(recordsToUpdate);
}
global class asyncApex {
@future
public static void processUpdate(List<SD_Member__c> sdList) {
update sdList;
}
}
you probably cannot pass list(non primitive) in future method.....this code might not work
If you want to pass the list in to future methods, just serialize using JSON mthods, and deserialize the list in future methods.