Activity Forums Salesforce® Discussions What is Database.SaveResult() in salesforce?

  • Aman

    Member
    July 31, 2017 at 10:40 am

    Hello shariq,

    The result of an insert or update DML operation returned by a Database method.

    Usage
    An array of SaveResult objects is returned with the insert and update database methods. Each element in the SaveResult array corresponds to the sObject array passed as the sObject[] parameter in the Database method, that is, the first element in the SaveResult array matches the first element passed in the sObject array, the second element corresponds with the second element, and so on. If only one sObject is passed in, the SaveResult array contains a single element.

    A SaveResult object is generated when a new or existing Salesforce record is saved.

    you can refer to this link:

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_saveresult.htm

     

  • Parul

    Member
    September 16, 2018 at 2:04 pm

    An array of SaveResult objects is returned with the insert and update database methods. Each element in the SaveResult array corresponds to the sObject array passed as the sObject[] parameter in the Database method, that is, the first element in the SaveResult array matches the first element passed in the sObject array, the second element corresponds with the second element, and so on. If only one sObject is passed in, the SaveResult array contains a single element.

    List<Database.SaveResult> updateResults = Database.upsert(arudate, false);
    for(Integer i=0;i<updateResults.size();i++){
    if (updateResults.get(i).isSuccess()){
    updateResults.get(i).getId();

    }else if (!updateResults.get(i).isSuccess()){
    // DML operation failed
    Database.Error error = updateResults.get(i).getErrors().get(0);
    String failedDML = error.getMessage();
    arudate.get(i);//failed record from the list
    system.debug('Failed ID'+arudate.get(i).Id);
    }

    }

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos