You need to sign in to do that
Don't have an account?
Developer script exception
Hello All,
I am getting a Developer script exception error on one of my triggers. The error states:
Apex script unhandled trigger exception by user/organization: XXXXXXXXXXXXXX/xxxxxxxxxxxxxx
Update_NCOA_Address_v01: System.LimitException: Too many DML statements: 151
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 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; 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); Update 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); Update 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); Update SD;} }}
What happens is, I send a between 3,000 and 5,000 records to a third party print vendor and they return their validity check results, the "none", "fowarded" or "failed" to their printsf_collateral_send_history__c object. As each record returns, the trigger updates fields on my custom object SD_Member__c.
I thought I had "bulkified" the trigger, but maybe not.
Thanks for the help,
Todd B.
Try this.
we just removed the DML from inside of the loop.
All Answers
List<SD_Member__c > records = new List<SD_Member__c >();
for() {
records.add(SD);
}
update records;
Thank you for your help Bhawani, but could you be a little more specific? I am new to coding.
Try this.
we just removed the DML from inside of the loop.