You need to sign in to do that
Don't have an account?
Alan Mc Carthy
Why can a DML statement insert a list of SObjects with 300 elements, but you can't make 300 DML statements simultaneously?
Hi folks,
I am asking about the theory involved here. What is the real difference between inserting a list of SObjects, and inserting Sobjects individually? Surely as long as the same number of records is going into the database, the operations should consume the same resources. For some code to show what I mean:
Thanks for you help!
I am asking about the theory involved here. What is the real difference between inserting a list of SObjects, and inserting Sobjects individually? Surely as long as the same number of records is going into the database, the operations should consume the same resources. For some code to show what I mean:
// Good List<Contact> myContacts = new List<Contact>(); for( Integer i = 0; i < 1000; i++) { Contact myContact = new Contact(LastName = 'John'); myContacts.add(myContact); insert myContacts; // Bad for( Integer i = 0; i < 1000; i++) { Contact myContact = new Contact(LastName = 'John'); insert myContact;So in the code the 'Good' example will avoid governer limits and the 'Bad' example will run into problems... but aside from the governer limits the database would end up identical in each example. So what exactly is going on here?
Thanks for you help!
updated code:
Now, as you can seen in the good example we are process 1000 record inside a for loop and add every records in List of contact List<Contact> and after the for loop process it will be make only 1 Insert DML call to server for insert the list,
and in you bad example we are call insert DML inside the for loop it's means this will make 1000 insert DML call to server and this will be throw error
i hope you understand the difference between good and bad example
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
Regards!
So @piyush, could I ask you to expand more? Why is 1000 calls to the server which insert one record each more expensive than one call to the server which inserts 1000 records?
Do you have any documentation about what is happening when a DML statement is made that could help me to understand?
Thanks.