Activity › Forums › Salesforce® Discussions › What is Database.SaveResult() in salesforce?
-
What is Database.SaveResult() in salesforce?
Posted by shariq on July 31, 2017 at 6:25 AMWhat is the basic definition of Database.SaveResult(), give an example?
Parul replied 7 years, 8 months ago 3 Members · 2 Replies -
2 Replies
-
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:
- [adinserter block='9']
-
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.