TransWikia.com

Insert multiple records using salesforce batch apex - DML Error

Salesforce Asked by Salesforce Tech Enthusiast on November 5, 2021

I am getting a DML error in the execute part of the Batch Apex – need a workaround, please

Query:
    select Id,Name from Account

Execute:
    for (Account a: acclist){
       -- need to insert 10 records for each day for next 1 year
       -- i.e 10x365=3650 records
       -- populate a list
    }
    -- insert the list populated above.
finish:
    -- send email

Now the problem is, if the Account query reaches the 3rd account, i get DML Error:10001..(i.e 3 x 3650 exceeds 10001).
But I need to do this for over 55 accounts.. i.e 55*10*365 total records.

One Answer

Each invocation of execute() takes place in a single transaction, and is subject to all of the standard limits for an asynchronous context. That includes the DML Rows limit at 10,000 records.

If you must insert this many records per Account, you'll need to reduce your batch size to 1 or 2.

That said, I'd seriously consider reevaluating this data model. Are you meaningfully using 10 records per day per Account? Can you potentially use other types of customization, like a custom UI, to avoid creating any records that may be more like placeholders?

Answered by David Reed on November 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP