I want to simulate LimitException error on StandardSetController which can only return max 10000 records. So I am trying to create a test method which creates more than 10000 records and then try to query them using StandardSetController.

I am trying to insert more than 10000 records in test method across 2 insert statements. Each insert statements in trying to insert around 6000 items. These insert DML statements are not wrapped around Test.StartTest() and Test.StopTest().

But I am getting too many DML rows 10001 error from the test method which tries to insert more tan 10000 item.

My understanding is, it should be possible to insert more than 10000 items as long as they are across multiple DML statements and each DML statement is trying to insert less than 10000 items.

Am I missing something ? How can I simulate this scenario ?

  • Limit exceptions can't be caught - see developer.salesforce.com/forums/… – cropredy Jan 9 '15 at 18:14
  • @crop1645 , thanks for the information that Limit exceptions can't be caught. I can still use aggregate query to check if my QueryLocator would return more than 10000 records before actually executing the query. I can take necessary action if there are going to be more than 10000 records. Bottom line is, I am trying to simulate scenario which can insert more than 10000 records and that is where I am having issues. – apn Jan 9 '15 at 18:21

The limit of 10000 DML rows does not apply to a single DML statement, but to the entire transaction. Because the two DML statements in question are involved in the same transaction, the DML rows from both count towards the limit.

Notice the title of the article, "Per-Transaction Apex Limits" https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

Your Answer

