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
Raj R.Raj R. 

What error is caused by inserting empty list?

Hi, i am still relatively new to DML operations such as insert. 

Let's say for whatever reason, my new list of leads is empty. What are the errors caused by inserting an empty list? Does Sf already know not to insert an empty list?

For example,

List<Lead> newLeads = new List<Lead>();

insert newLeads;

Is it recommended that I use the ".isEmpty()" method to only perform an Insert operation when the list is not empty?

if( !(newLeads.isEmpty())
insert newLeads;
Best Answer chosen by Raj R.
kiranmutturukiranmutturu
Yes , in these cases they are clear enough to handle this.  if you simply insert empty list with out check salesforce will not do DML on the empty list.

All Answers

kiranmutturukiranmutturu
Yes , in these cases they are clear enough to handle this.  if you simply insert empty list with out check salesforce will not do DML on the empty list.
This was selected as the best answer
Raj R.Raj R.
Thanks Kiran_mutturu for clarifying