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

Data Base Class Methods:

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);

}

}

}

}

Our Recent Blog

Share This Post