Free Salesforce Developers Tutorials >

Chapter 8 - Apex DML and Database Methods >

Database Class Method Result Object

Database Class Method Result Object

What You’ll Learn


tickDatabase Classes and Methods

S2 Labs

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:

OperationResult Class
Insert, updateSave Result Class
upsertUpsert Result Class
mergeMerge Result Class
deleteDelete Result Class
undeleteUndelete Result Class
convertLeadLead Convert Result Class
emptyRecycleBinEmpty 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);
            }
        }
    }
}
Salesforce Developer

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *