I am inserting a milliions of Emplyoee details in to a table with batch operation as 1000 records per batch. Even a record failed to insert still executeBatch() method executes the remaining statements added to batch. But how can we track the failed record?
For eaxample in first 1000 records 50th record is failed to insert even though remaining 950 records inserted successfully. Now I want to track the 50th record which is failed.
Number of affected rows before Batch Error :: 999
Number of affected rows not available: 0
Failed Count in Batch because of Error: 1
Here For first batch of 1000 records 800th record is made exception but remaining records in batch continued to insert so 999 records affected in DB and 1 record failed (i.e., 800th record) to insert. Then No Batch added as Exception raised in first batch. Here I am able to find count of records which are success and failed but not the exact record which is failed.
"you may ask that 800th gets failed, but i know that manually its a wrong one."
The Below code will print the index position of failed record
Failed to execute record at: 800
So we can get the index of failed record. Can't we get this record values like Employee Name etc...???
Joined: Mar 17, 2012
Find one record that failed and compare the values from your list of employees at the given position. e.g print out the employee at employee.get(i) and surrounding values and check if it matches with the reported index.