Database Class Method Result Object
Chapter Topics
- What Is DML In Salesforce?
- Insert | APEX DML Standalone Statements
- Update | APEX DML Standalone Statements
- Upsert | APEX DML Standalone Statements
- Delete | Apex DML Standalone Statement
- Undelete | Apex DML Standalone Statement
- Merge | APEX DML Standalone Statements
- APEX DML Statements Best Practices
- Database Class in APEX
- Empty Recycle Bin
- Count Query | Method in Apex Database Class
- Lead Conversion | Method in Apex Database Class
- Transaction Control and Rollback
- Database Class Method Result Object
What is a Database class?
A database class is a class that consists of methods that can help us to make changes in the database or to fetch data from the database.
What Is Database Class Method Result Object?
Database class methods returns the result of data operations. These result object contain useful information about data for each record such as whether the operation is successful or not and any other information.
Each type of operations returns a specific result object type, following are:
Operation | Result Class |
Insert, update | Save Result Class |
upsert | Upsert Result Class |
merge | Merge Result Class |
delete | Delete Result Class |
undelete | Undelete Result Class |
convertLead | Lead Convert Result Class |
emptyRecycleBin | Empty Recycle Bin Class Result |
Database Class Method Example
public static void main() {
List < Account > accList = new List < Account > ();
for (integer i = 0; i < 10; i++) {
accList.add(new Account(name = ’Result Test’ + i, numberOfEmployees = i));
accList.add(new Account());
insert accList;
}
System.debug(‘Total Accounts: ’+accList.size());
Database.SaveResult[] saveList = Database.insert(accList, false);
for (Database.SaveResult s: saveList) {
If(s.isSuccess())
System.debug(‘I was successful = ’+s.getID());
else {
System.debug(‘I was Unsuccessful = ’+s.getID + ’because of following errors’);
for (Database.error dr: s.getErrors()) {
System.debug(dr.getStatusCode() + ’’ +dr.getMessage());
System.debug(‘fields affected by insertion are: ’+dr.getFields);
}
}
}
}

Join our newsletter: Get daily update on Salesforce career insights & news!
Join Now!
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.