You need to sign in to do that
Don't have an account?
tulasiram ch
global class batchForinsertingAccounts implements Database.Batchable<sObject>, Database.Stateful{
global integer count;
global string query;
global Database.QueryLocator start(Database.BatchableContext BC){
count=0;
return null;
}
global void execute(Database.BatchableContext BC, List<account> scope){
count=0;
list<Account> Llist = new list<Account>();
for(account acc:scope){
for(integer i=0;i<=20000 ;i++){
Account a = new account();
a.name = 'TulasiRam'+i;
Llist.add(acc);
count++;
}
}
database.insert(Llist);
}
global void finish(Database.BatchableContext BC){
system.debug(''+count);
}
}
I used following batch apex for inserting 20000 records but i am gettong null exception pls suggest me
global class batchForinsertingAccounts implements Database.Batchable<sObject>, Database.Stateful{
global integer count;
global string query;
global Database.QueryLocator start(Database.BatchableContext BC){
count=0;
return null;
}
global void execute(Database.BatchableContext BC, List<account> scope){
count=0;
list<Account> Llist = new list<Account>();
for(account acc:scope){
for(integer i=0;i<=20000 ;i++){
Account a = new account();
a.name = 'TulasiRam'+i;
Llist.add(acc);
count++;
}
}
database.insert(Llist);
}
global void finish(Database.BatchableContext BC){
system.debug(''+count);
}
}
You can't insert new records in the batch apex.Batch Apex is to manipulate the data.Use Normal Utility class or Queueable
All Answers
You can't insert new records in the batch apex.Batch Apex is to manipulate the data.Use Normal Utility class or Queueable
for(integer i=0;i<=20000 ;i++){
Account a = new account();
a.name = 'TulasiRam'+i;
Llist.add(a);
Llist.add(acc);count++;
}
Minimal test:
Id batchInstanceId = Database.executeBatch(new batchForinsertingAccounts());
system.debug('instance id:' + batchInstanceId);
Regards
Alain