+ Start a Discussion
deeput05deeput05 

insertion

Hi,

 

can i have code for insertion of 11,000 records  at a time without using batch apex

JitendraJitendra

Hi Deepu,

 

Just create the list of records you want to insert and using single DML statement you can insert it.

 

Example :

List<Temp__c> tmpList = new List<Temp__c>();

for(Integer i=0;i<12000,i++)
{
  Temp__c obj = new Temp__c();
  obj.Name = String.valueOf(i);
  tmpList.add(obj);
}

insert tmpList;

 

deeput05deeput05

it allows only to create 10000 records not more than tht

JitendraJitendra

I dont think that there is any limit like 10,000 in single insert.

 

Now it depends on Heap memory size. Can you please provide documentation link if you find that there is limit of 10,000 records in single insert statement

deeput05deeput05

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_insert.htm

 

i am unable process more than 10000 record it is throwing a dml error

JitendraJitendra

I have also tried to replicate. You can only have 10000 DML operations so only option with you is "Batch Apex" or "Scheduled Job"

SamuelDeRyckeSamuelDeRycke

Or just use multiple dml statements ?, if you're sure the amount of records /  10k won't ever reach the limit on dml statements you can make. But, you can verify so in apex.

 

update: wrong  info. was confusing different limits.

 

 

JitendraJitendra

Even multiple DML will not work. In single request only 10000 DML operations are allowed.

SFFSFF

So break it up:

 

list<Temp__c> tmpList = new list<Temp__c>();

for (Integer i=0; i<12000; i++)
{
  Temp__c obj = new Temp__c();
  obj.Name = String.valueOf(i);
  tmpList.add(obj);
  if (tmpList.size() >= 10000)
  {
    insert tmpList;
    tmpList.clear();
  }
}
if (tmpList.size() > 0) insert tmpList;

SFDC would be a crap platform if you couldn't insert more than 10K records. If you need to do more than 1MM records, this won't work, of course - then you have to use @future or batch.

 

Good luck!

JitendraJitendra

Even above solution will not work.. In Single transaction 10,000 is upper limit. You have to use Batch Apex in this case

SammyComesHereSammyComesHere

May be you can use a combination of synchronous and asyncronous Apex to solve this problem . Use a List for inserting intial 10000 records and @future for remaining record.

 

There wont be much delay in that i believe and it happens seaminglessly.