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
vijay sampathivijay sampathi 

how to create 50 thousand and more record in sobject from anonymous block

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Vijay,

When ever your requirement needs to process more than 50,000 records at a time, a trigger might not be your best bet. it's always safe to go with async processing like @future, batch etc

If you don't need an immediate processing, a batch + scheduled apex can do wonders. 

Another work around is .... (not very advisable) 

Create a VF page,

--> on click of the button --> Execute code --> then use javascript to click the button as many times you need to use the data...
you'll be able to use the OFFSET parameter in SOQL.. this is a workaround only as a last resort... this helps you process things synchronously.. but the only disadvantage is that it needs a user to open the VF in a browser... ( might work for some use cases)

Please refer the below link for reference.
https://success.salesforce.com/answers?id=90630000000hNXkAAM

I hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
vijay sampathivijay sampathi

CLASS
public class insert20{
public void m1()
{
list<ticket__c>ticket=new list<ticket__c>();
ticket__c objtest;
for(integer i=1;i<=20;i++)
{
objtest=new ticket__c(name='ticket'+string.valueof(i));
ticket.add(objtest);
}
insert ticket;
}
}



in anonymous block you write this code
insert20 obj=new insert20();
obj.m1();