Skip to main content

Hi,

 

Could you please share in detail why this code throw the below error : " Too many DML statements: 151"

 

for (Account thisAccount :[select id,industry from Account limit 150])     {     if (thisAccount.industry =='Technology')     {thisAccount.industry ='Technology Related';          }     update thisAccount; }

 

Here a only have 1 SOQL query and DML statement.

 

Also can you please help me to see how much time the DML executed in debug log?

 

Thanks

 

#Salesforce  #Salesforce Developers  #Salesforce Developer  #Developer Forums  #Developer Beginner  #Developer Edition  #Developers  #DeveloperForce Toolkit

11 answers
  1. Jul 31, 2021, 12:56 PM

    Hi @Abdullah Abdullah this code shouldn't have thrown the DML 151 error as it is exactly making 150 DML Operations. but you are Updating Accounts it may so happen it might be making some other process to run which might be performing Update or any other database operation. but all of this is happening in a single transaction so it hit the DML limit. if you really want to understand what other activity is happening you need to trace your Logs. other ways are analyzing the debug in perspective mode. once you run this code in an anonymous window  view your log in analysis mode for that goto-> debug -> change perspective to the analysis refer bellow

     

    Hi this code shouldn't have thrown the DML 151 error as it is exactly making 150 DML Operations.

     

    one you are in analysis mode you can analyze better what operation was performed and all

     

    Debug 2.JPG

     

    To see the Limits you will have to change the debug level to Finest then you can see limits in the 2nd tab

     

    Debug 3.JPG

     as you can see your exact code didn't throw an exception as it exactly consumed 150 DML. in your org it is doing some extra updates. run the code in new org with 150 accounts it will not throw an exception.

     

    Hope it answers your questions. the crux of this discussion is we should write code with the best Practice to avoid hitting such limits

    Regards,

    Happy learning

0/9000