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
ch ranjeethch ranjeeth 

how to insert 1 millions records using batch apex?

sfdc Beginnersfdc Beginner
Use Database.QueryLocator to insert 1 Million Records through Batch Apex.

If this Solces your Problem, Then select my Answer as Best Answer. So that it may helpful for Others!!
ch ranjeethch ranjeeth
Please give somw sample code
Anilkumar KotaAnilkumar Kota
Here is the sample code for inserting records.
global class InsertAccountContactimplements Database.Batchable<sObject>{
     global ExampleBatchClass(){
                // Batch Constructor
     // Start Method
     global Database.QueryLocator start(Database.BatchableContext BC){
     String Query = ''; // Generate your string query on any object here with limit 10000
      return Database.getQueryLocator(Query); //Query is Required on object which you want to run Batch
   // Execute Logic
    global void execute(Database.BatchableContext BC, List<sObject>objlist){
    List<Account> acclist = new List<Account>();
list<Contact> conlist = new list<contact>()
          for(Sobject obj: objlist){
                Account acc = new account();
       = 'testname';
       insert acclist;
    for(Account acc : Acclist){
          Contact con = new Contact();
           con.lastname = 'testname';
           con.accountid =;
   Insert conlist;
    global void finish(Database.BatchableContext BC){
         // Logic to be Executed at finish

You can insert 100000 contact and account record in same batch class, But it also depends on your requirment. 
You can use data loader or import wizard for the same. 
Data Loader autometically inserts records in batches.