+ Start a Discussion
force shahidforce shahid 

How to capture the data from database.saveresult

HI Friends,

I written a trigger for importing the CSV file into custom object . While importing into custom object these records are also insert / update in Contact & Lead object also.
I have to give the report to sales team as how many records inserted in Contact & how many updated .Same thing Leads also.

When i import CSV file directly into Contact / Lead then i got info how many iserted & updated. 
But here i am importing records into custom object then how can i find.

I wrriten some code , with this code i got the info of result of importing file in debug only log file. I need to give this file to admin.

Also i need to fetch the data from geterrors.  

Code :

 if (upcon.size() > 0){
        System.debug('Update Contact Size:-'+upcon.size());
        Database.saveResult[] rslt=Database.update(upcon, false);
        for(Database.saveResult r: rslt){
            if(r.isSuccess()){
                System.debug(r.getId());
            }
            else{
                  for(Database.Error err : r.getErrors()){
                    System.debug('The following error has occurred.');                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('Contact fields that affected this error: ' + err.getFields());
                }
            }
        }
    }
NagendraNagendra (Salesforce Developers) 
Hi,

May I suggest you please check with below links which might help you accelerate further with the above requirement.
 
https://salesforce.stackexchange.com/questions/54737/database-saveresult-getid-returns-null

https://salesforce.stackexchange.com/questions/73255/saveresult-get-failed-records-on-insert

https://salesforce.stackexchange.com/questions/42417/how-to-capture-those-records-that-was-unable-to-get-inserted

https://developer.salesforce.com/forums/?id=906F00000008xnlIAA

Thanks,
Nagendra