I suggest writing a unit test to test your logic. Just keep in mind that you can only run the execute method once (ie. pass only a single batch) when writing a unit test for a batchable class.
batchApex obj = new batchApex(); Database.executeBatch(obj,2000);
When i Run this code it is showing error First error: Too many DML rows: 10001
Using bath apex we can process 5 millionrecords right.Why it showing DML error.
public class batchApex implements Database.Batchable<sobject> { public static List<account> aclist = new List<Account>(); public static Database.QueryLocator start(Database.BatchableContext bc){ return Database.getQueryLocator('select Name From Account'); } public static void execute(Database.BatchableContext bc,List<Account> accList){
for(integer i=0;i<50002;i++){ Account acc = new Account(); acc.Name='Test'+i; acc.AccountNumber='1234567'; aclist.add(acc); } insert aclist; } public static void finish(Database.BatchableContext bc){
using batchapex we can update upto 50million records.
please check below sample code:
here in each batch it will tke 2000 records.
Using dtaloader we can update up to 5 million records.please let me know in case any help.
Thanks
Varaprasad
Can I do this while I am already using a batch apex class to query more than 50,000 records, and where I am looking over two objects?
i.e. can I add this to my code below?
The limit for the number of SOQL queries you can execute is separate from the limit for the number of DML statements you can execute, but you cannot update more than 10,000 records in a single batch (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm).
I suggest writing a unit test to test your logic. Just keep in mind that you can only run the execute method once (ie. pass only a single batch) when writing a unit test for a batchable class.
batchApex obj = new batchApex();
Database.executeBatch(obj,2000);
When i Run this code it is showing error
First error: Too many DML rows: 10001
Using bath apex we can process 5 millionrecords right.Why it showing DML error.
public class batchApex implements Database.Batchable<sobject> {
public static List<account> aclist = new List<Account>();
public static Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('select Name From Account');
}
public static void execute(Database.BatchableContext bc,List<Account> accList){
for(integer i=0;i<50002;i++){
Account acc = new Account();
acc.Name='Test'+i;
acc.AccountNumber='1234567';
aclist.add(acc);
}
insert aclist;
}
public static void finish(Database.BatchableContext bc){
}
}