You need to sign in to do that
Don't have an account?

How to insert failed records into new custom object and how to reprocess them in batch class.
if(!conList.isEmpty()){ Database.SaveResult[] srList = Database.insert(conList, false); system.debug('srList'+srList); integer size=srList.size(); system.debug('srList size'+size); List<Database.SaveResult> Result=srList; //Failed Records failedconlist=new List<contact>(); for (Integer i = 0; i<srList.size(); i++) { Database.SaveResult s = Result[i]; contact origRecord = conList[i]; system.debug('origRecord'+origRecord); if(!s.isSuccess()){ failedconlist.add(origRecord); // List<Database.Error> err= s.getErrors(); ErrorLog__c log=new ErrorLog__c(); log.AccountId__c= origRecord.Accountid; log.AccountName__c=origRecord.Account.Name; for(Database.Error err : s.getErrors()) { // log.ErrorStatusCode__c=err.getStatusCode(); // log.ErrorMessage__c=err.getMessage(); // log.ErrorFields__c=err.getFields(); } logList.add(log); } }
Hello Experts ,
i have batch class which will insert thousand's of records .so if some records fail i am trying to insert into error log object .
Help Needed :
1.while i am creating these records into custom object i am not able to insert error messages from DataBase.saveresult .
2.After inserting how to re-process them other than manual process .
Below is my sample code :
when i try to assign errormessage or statuscode to text fileds to not allowing .
Please give me some sample code or suggestion .
Thankyou in advance.
Please refer the below code which contains the logic which fulfills your need.
please let me know if you need more clarifications.
Thanks
Arun
Thanks - that makes sense, and is helpful - it's just such a shame that such processes are necessary. Surely, it should be easier than this!