function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James George 00700James George 00700 

Database.Insert and Limit Exception

Hi Friends,
I was trying a test code to insert 50,000 records using the below code, its throwing the limit exception related to dml rows of 10000 reached.

My question is since I specified  false as below
Database.SaveResult[] srList = Database.insert(lstContacts, false);
is this code suppose to insert at least 10000 records, but did'nt do it.

Let me know your comments.


My code below
List<Contact> lstContacts = new List<Contact>();
for(Integer x = 0; x<50000; x++ ){
    Contact con = new Contact(LastName= 'Keller'+x, FirstName='Helen'+x);
    lstContacts.add(con);
}
Database.SaveResult[] srList = Database.insert(lstContacts, false);

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()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Account fields that affected this error: ' + err.getFields());
        }
    }
}

Thanks
JG
 
Best Answer chosen by James George 00700
Annu ChoudharyAnnu Choudhary
Hi James George,
Salesforce fixed the limit to process only 10000 records in one transaction by dml. Only you can insert 10000 records.

for(Integer x = 0; x<10000; x++ ){
  Contact con = new Contact(LastName= 'Keller'+x, FirstName='Helen'+x);
  lstContacts.add(con);
}


For more apex governer limit please see at below link.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

Please select as a best answer if it is work for you. So it help others.

Thanks,
Annu Choudhary

All Answers

Jyoti NaiduJyoti Naidu
Good night pics - In this post, we provide beautiful good night pics. Download and share your friends and family and loved ones. I think this HD good night message image liked by you.The night is the best time for rest. When you see wishes form your friends form your mobile you became very happy. Wish your loved ones with good night photo.
visit for more info -- https://www.imagesgoodnight.com/
Annu ChoudharyAnnu Choudhary
Hi James George,
Salesforce fixed the limit to process only 10000 records in one transaction by dml. Only you can insert 10000 records.

for(Integer x = 0; x<10000; x++ ){
  Contact con = new Contact(LastName= 'Keller'+x, FirstName='Helen'+x);
  lstContacts.add(con);
}


For more apex governer limit please see at below link.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

Please select as a best answer if it is work for you. So it help others.

Thanks,
Annu Choudhary
This was selected as the best answer
David Mark 11David Mark 11
AOL Mail is well known for its fully secure, reliable and lightning-fast email services. It gives you some of the best features, excellent tools and user-friendly interface that the latest technology can afford. In order to experience the performance of this outstanding mailing service, you can opt for the convenient AOL Mail services.  
 
James George 00700James George 00700
Hi Annu,
Thanks for your reply and the link.
So the assumption is even with parameter of false, we still cannot catch the limit exception, is that true?
David Zhu 🔥David Zhu 🔥
When the test code hits Governor Limit, it terminates the entire transaction. No other Apex code will be excuted in the same transaction. Apex code cannot catch Governor Limit Exception. 
James George 00700James George 00700
Thanks David and Annu