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
Sfdc@SmithaSfdc@Smitha 

find the error in code

Hi

 

 pls find the error in the below code can anybody help me?

 

public class insst1
{

    public void sav()

{

for(integer i=0;i<250;i++)
{
Lead c=new lead();
c.FirstName='Mr'+i;
c.company='XYZ';
insert c;
}

    }
}

MagulanDuraipandianMagulanDuraipandian

for Lead, LastName is mandatory...

You cannot insert more than 150 records as governor limit for DML statement is 150...

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

SFDC Blog

If this post is your solution, kindly mark this as the solution.

SFFSFF

You are doing DML (insert) inside of the loop. Instead, try something like this:

 

list<Lead> insertLeads = new list<Lead>();
for (integer i=0; i<250; i++)
{
  Lead l = new Lead();
  l.FirstName = 'Mr' + i.format();
  l.LastName = 'Lead';
  l.company = 'XYZ Company';
  insertLeads.add(l);
}
insert insertLeads;

 

Sfdc@SmithaSfdc@Smitha

Thanku for reply.